the-botman Posted September 30, 2012 Share Posted September 30, 2012 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 Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 1, 2012 Share Posted October 1, 2012 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. Quote Link to comment Share on other sites More sharing options...
the-botman Posted October 1, 2012 Author Share Posted October 1, 2012 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> Quote Link to comment Share on other sites More sharing options...
the-botman Posted October 1, 2012 Author Share Posted October 1, 2012 see this code i am trying works but removes all java scripts from the source code, i just need the above code removed $page = preg_replace('/<script(.*?)<\/script>/is','',$page); Quote Link to comment Share on other sites More sharing options...
Christian F. Posted October 1, 2012 Share Posted October 1, 2012 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.