Jump to content

preg reg help


Vivid Lust

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.