Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何用php替换句子中的某些单词_Php - Fatal编程技术网

如何用php替换句子中的某些单词

如何用php替换句子中的某些单词,php,Php,假设我有这样一句话:“奥巴马总统和他的家人从非洲回到美国” 我如何用“布什”取代“奥巴马”?这是一个愚蠢的问题。如果你只是在谷歌上搜索一下,就会找到解决方案: str_replace(混合$search、混合$replace、混合$subject[、int和$count]) 使用函数: $sentence = "The president obama came back to america from africa with his family"; $changed = str_replace

假设我有这样一句话:“奥巴马总统和他的家人从非洲回到美国”


我如何用“布什”取代“奥巴马”?

这是一个愚蠢的问题。如果你只是在谷歌上搜索一下,就会找到解决方案:

str_replace(混合$search、混合$replace、混合$subject[、int和$count])

使用函数:

$sentence = "The president obama came back to america from africa with his family";
$changed = str_replace("obama", "bush", $sentence);

您阅读了str_replace()()的文档,然后尝试在代码中使用该函数。这个问题并不愚蠢。我看到这个问题的唯一问题是OP没有尝试任何东西。谢谢。但这是我的错。我只是随便问了一个问题,什么也没试。这不会再发生了。我将来会尽我最大的努力。:)
$sentence = "The president obama came back to america from africa with his family";
$changed = str_replace("obama", "bush", $sentence);