Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/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_String_Replace - Fatal编程技术网

在PHP中替换字符串中的字符串

在PHP中替换字符串中的字符串,php,string,replace,Php,String,Replace,我想在PHP中替换字符串中的字符串。它应该找到完全匹配的。 例如,如果有一个字符串 $string=“a b cd e f” 我的功能是 replace(“abc”,“1233”,“$string”) 这可以用PHP实现吗?我已经试过str_replace()。$string=str_replace(“a b c”,“1 2 3”,“$string”)应该可以工作。那么str_replace()有什么问题?您需要将替换结果分配给一个变量。它不会更改变量$string本身。您所说的“替换字符串中的

我想在PHP中替换字符串中的字符串。它应该找到完全匹配的。 例如,如果有一个字符串

$string=“a b cd e f”

我的功能是

replace(“abc”,“1233”,“$string”)


这可以用PHP实现吗?我已经试过str_replace()。

$string=str_replace(“a b c”,“1 2 3”,“$string”)应该可以工作。

那么
str_replace()
有什么问题?您需要将替换结果分配给一个变量。它不会更改变量
$string
本身。您所说的“替换字符串中的字符串”是什么意思?。