开发者

I have an array on strings in php. I want to replace all occurrences of those strings with another string within a block of text

开发者 https://www.devze.com 2023-01-09 12:50 出处:网络
I have an array that contains several domain names. I need to replace those domains inside block开发者_如何学运维s of text (forum posts) with another string, if any of them actually appear inside that

I have an array that contains several domain names. I need to replace those domains inside block开发者_如何学运维s of text (forum posts) with another string, if any of them actually appear inside that forum post.

Whats the best way of doing that? I can't alter the array that contains a list of domains it would search for. Its stored as follows:

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


Try with str_replace http://www.php.net/manual/en/function.str-replace.php


$modified_haystack = str_replace($domain_list, $repl, $haystack);

$repl is the replacement text, $haystack is the text to search.

0

精彩评论

暂无评论...
验证码 换一张
取 消