Vivid Lust Posted September 30, 2010 Share Posted September 30, 2010 Hi all, I'm wanting to replace all the "translation.asp?tranword=" in a string. I have this but it is currently not replacing it. String: <a href='translation.asp?tranword=dove'>dove</a><br><a href='translation.asp?tranword=diver'>diver</a><br><a href='translation.asp?tranword=dive'>dive</a><br><a href='translation.asp?tranword=Dave'>Dave</a><br></td><td><a href='translation.asp?tranword=drover'>drover</a> What i have: $content = preg_replace('/translation.asp?tranword=/i', 'wordreference.php?word=', $content); Can anyone help? Jake Link to comment https://forums.phpfreaks.com/topic/214819-preg-reg-help/ Share on other sites More sharing options...
bob.newtek Posted September 30, 2010 Share Posted September 30, 2010 You need to escape the special characters in there: $content = preg_replace('/translation\.asp\?tranword=/i', 'wordreference.php?word=', $content); Also, it looks like in this case that you don't even need to use a regex, but rather a simple string function that will be much faster: $content = str_ireplace('translation.asp?tranword=', 'wordreference.php?word=', $content); Link to comment https://forums.phpfreaks.com/topic/214819-preg-reg-help/#findComment-1117627 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.