I am trying to use a regular expression to replace any domain in a string with another domain but it isn’t working yet.
I tested the RegEx part on regexpal.com and it seems to be working.
Here is my code:
$itemdesc = str_replace("([a-z0-9\-]+).(com|net|org|co|cm|info|cc)\s\i","Example.com",$itemdesc);
Please Help! Thanks in advance
You need delimiters and preg_replace:
Note the slashes at either end – the modifiers following the last delimiter
Also note, the delimiters can be any character – try to use a character that isn’t used in your regular expression, otherwise it’ll need to be escaped everywhere.