假设我有这句话:“奥巴马总统和他的家人从非洲回到美国”。
如何将“奥巴马”替换为“布什”?
使用str_replace()函数:
$sentence = "The president obama came back to america from africa with his family";
$changed = str_replace("obama", "bush", $sentence);
那是一个愚蠢的问题。如果你只是用谷歌搜索它,会找到解决方案:
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);