替换&在PHP中的char

时间:2012-03-21 07:38:38

标签: php

我想将google&堆栈替换为谷歌和堆栈。请指导我

3 个答案:

答案 0 :(得分:2)

$str =  str_replace('google&stack', 'google and stack', $str);

$str =  str_replace('&', ' and ', $str);

答案 1 :(得分:1)

这应该有效

$string = "google & stack";
$string = str_replace(" & "," and ",$string);
$string = str_replace("&"," and ",$string);

返回google&堆

它在$string = google&stack"

时也有效

编辑(因为您更改了问题):

$string = "google&stack";
str_replace("google&stack","google and stack",$string)

答案 2 :(得分:1)

这对我有用:

echo str_replace("&","and","facebook&google");