2

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

<script type="text/javascript"><!--
google_ad_client = "pub-";
/*Top 468x15 */
google_ad_slot = "";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">

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

2
  • 3
    Just drop the comments; they are not needed these days. stackoverflow.com/questions/4421599/… Commented Feb 28, 2012 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? Commented Feb 28, 2012 at 8:30

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.