views:

23

answers:

2

I have an array that contains several domain names. I need to replace those domains inside blocks 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");
+2  A: 

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

robertbasic
Combined with a foreach loop.
Blair McMillan
@Blair, you don't need a loop, since `str_replace` accepts arrays.
Matthew Flaschen
A: 
$modified_haystack = str_replace($domain_list, $repl, $haystack);

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

Matthew Flaschen