Take the 2-minute tour ×

I am using google ad in my site as given below.

google_ad_client = "pub-";
/*Top 468x15 */
google_ad_slot = "";
google_ad_width = 468;
google_ad_height = 15;
<script type="text/javascript"

This code is from the admin side which cannot be altered(site architecture is like that), The ad will not displays if the html comment is there, but it displays when i replace the html comment in the js with null before displaying it. Now the problem is if any other html coments are there in the page my str_replace code replaces that too. and the orginal html comment display as plain text. Any solution for this? please help. thanks

share|improve this question
Just drop the comments; they are not needed these days. stackoverflow.com/questions/4421599/… –  The Nail Feb 28 '12 at 7:47
I know, but i can't do that because it is the content added from the admin side. any other option to remove the comment tag in script only? –  Soji Feb 28 '12 at 8:30

1 Answer 1

I understand that your architecture allows you to do a global search and replace on the complete page and you are replacing just the HTML comment markers <!-- and -->, right?

Why don't you simply search for the string <script type="text/javascript"><!-- and replace it with just the script tag <script type="text/javascript"> instead? You won't even need to replace the closing selector since it's commented out and should not interfere with any of your script functionality.

share|improve this answer
I tried that too, $string = str_replace('<script type="text/javascript"><!--','<script type="text/javascript">',$string); This is the code i used but it is not worked –  Soji Feb 28 '12 at 9:16

Your Answer


