Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.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_Replace - Fatal编程技术网

我在php中有一个字符串数组。我想用文本块中的另一个字符串替换所有出现的字符串

我在php中有一个字符串数组。我想用文本块中的另一个字符串替换所有出现的字符串,php,replace,Php,Replace,我有一个包含多个域名的数组。我需要用另一个字符串替换文本块(论坛帖子)中的那些域,如果它们中的任何一个确实出现在论坛帖子中的话 最好的方法是什么?我无法更改包含它将搜索的域列表的数组。其存储方式如下: $domain_list = array("domain1.com", "domain2.com", "domain3.com"); 尝试使用str\u替换尝试使用str\u替换 $repl是替换文本,$haystack是要搜索的文本 $repl是替换文本,$haystack是要搜索的文本。与f

我有一个包含多个域名的数组。我需要用另一个字符串替换文本块(论坛帖子)中的那些域,如果它们中的任何一个确实出现在论坛帖子中的话

最好的方法是什么?我无法更改包含它将搜索的域列表的数组。其存储方式如下:

$domain_list = array("domain1.com", "domain2.com", "domain3.com");

尝试使用
str\u替换

尝试使用
str\u替换

$repl
是替换文本,
$haystack
是要搜索的文本


$repl
是替换文本,
$haystack
是要搜索的文本。

与foreach循环相结合。@Blair,你不需要循环,因为
str\u replace
接受数组。与foreach循环相结合。@Blair,你不需要循环,因为
str\u replace
接受数组。
$modified_haystack = str_replace($domain_list, $repl, $haystack);