-1

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

如何将“奥巴马”替换为“布什”?

4

2 回答 2

3

使用str_replace()函数:

$sentence = "The president obama came back to america from africa with his family";
$changed = str_replace("obama", "bush", $sentence);
于 2013-03-09T21:54:03.407 回答
1

那是一个愚蠢的问题。如果你只是用谷歌搜索它,会找到解决方案:

str_replace ( 混合 $search , 混合 $replace , 混合 $subject [, int &$count ] )

$subj  = "The president obama came back to america from africa with his family";
$search = "bush";
$replace   = "obama";

echo str_replace($search, $replace, $subj);
于 2013-03-09T21:53:09.240 回答