Jump to content

Preg_Replace


the-botman

Recommended Posts

heya everyone... ok im trying to replace multiple lines using preg_replace but its just not working please tell me what i am doing wrong here is my code

$page = preg_replace('<script>
if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
{
document.getElementById("toolbar_h").innerHTML = "<a href=\"https://addons.mozilla.org/firefox/downloads/file/148244/site_toolbar-initial.rev194-fx.xpi?src=dp-btn-primary\" rel=\"nofollow\" onclick=\"dlreg('','')\"><img src=\"http://site.com/img/toolbar_firefox_small.png\" border=\"0\" /></a>";
}
else
{
document.getElementById("toolbar_h").innerHTML = "<a href=\"http://site.com/crawler/extensions/chrome/mp3se.crx\" rel=\"nofollow\" onclick=\"chrome.webstore.install(); dlreg('',''); return false;\"><img src=\"http://site.com/img/toolbar_chrome_small.png\" border=\"0\" /></a>";
}
</script>','new ad code goes here',$page);

Thanks in advance

Zain

Link to comment
Share on other sites

preg_replace takes a regular expression that is properly formatted with delimiters. Plus, I think you need to escape the forward slashes with backslashes. Kinda hard to verify if the expression is even close without seeing an example of the code to be replaced.

Link to comment
Share on other sites

the code im trying to replace is

<script>if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){document.getElementById("toolbar_h").innerHTML = "<a href=\"https://addons.mozilla.org/firefox/downloads/file/148244/site_toolbar-initial.rev194-fx.xpi?src=dp-btn-primary\" rel=\"nofollow\" onclick=\"dlreg('','')\"><img src=\"http://site.com/img/toolbar_firefox_small.png\" border=\"0\" /></a>";}else{document.getElementById("toolbar_h").innerHTML = "<a href=\"http://site.com/crawler/extensions/chrome/mp3se.crx\" rel=\"nofollow\" onclick=\"chrome.webstore.install(); dlreg('',''); return false;\"><img src=\"http://site.com/img/toolbar_chrome_small.png\" border=\"0\" /></a>";}</script>

Link to comment
Share on other sites

If you only need the exact string above removed, use str_replace () instead. Regular Expressions should only be used if some of the content is dynamic, and thus cannot be expressed as a static string.

 

As far as escaping forward slashes, that's only needed if you use them as the delimiters. Otherwise they have no special meaning in RegExps.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.