Put adsense code inside php

Discussion in 'PHP' started by florimi, May 14, 2010.

  1. #1
    Hello!
    I am trying to put adsense code inside php page but i always receive "Unexpected t_string" error message.

    Let assume my adsense is this:

    <script type="text/javascript"><!--
    google_ad_client = "pub-000000000000000";
    /* 468x15, created 5/14/10 */
    google_ad_slot = "0000000000";
    google_ad_width = 468;
    google_ad_height = 15;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>

    What should i put before and at the end of the adsense code to make it work?

    Thank you for any help
     
    florimi, May 14, 2010 IP
  2. Christian Little

    Christian Little Peon

    Messages:
    1,753
    Likes Received:
    80
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It's because your using the echo statement to output the code. All those quotes in the javascript code are messing up the echo function. Try escaping all the quotes in the google code (" become \").
     
    Christian Little, May 14, 2010 IP
  3. florimi

    florimi Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    HI, Thank you for prompt reply.
    Could be that modification against Google TOS ?
    Thanks.
     
    florimi, May 14, 2010 IP
  4. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #4
    
    <?
    
    $adsense = '
    <script type="text/javascript"><!--
    google_ad_client = "pub-000000000000000";
    /* 468x15, created 5/14/10 */
    google_ad_slot = "0000000000";
    google_ad_width = 468;
    google_ad_height = 15;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    ';
    
    echo $adsense;
    
    ?>
    
    
    PHP:
     
    MyVodaFone, May 14, 2010 IP
  5. Christian Little

    Christian Little Peon

    Messages:
    1,753
    Likes Received:
    80
    Best Answers:
    0
    Trophy Points:
    0
    #5
    No it isn't, most webmasters do it because most websites run on PHP or some CMS and you have to modify the JS code so that it can be spat out by the programming language. The only way to violate Google's TOS is to a) conceal parts of the adsense block, or b) click ads on your own site.
     
    Christian Little, May 14, 2010 IP
  6. slimjim2010

    slimjim2010 Peon

    Messages:
    245
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The only thing that matters with Google Adsense TOS, is that the finished output (source code) doesn't change.

    Verify, by looking at your webpage sourcecode in your browser...
     
    slimjim2010, May 14, 2010 IP
  7. florimi

    florimi Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thank you very much guys...
    It works now :)
     
    florimi, May 14, 2010 IP
  8. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #8
    Another one is save the code in a html file say
    adsense.html

    and now call it using include

    This is so simple.
    You can modify adsense.html at any time to update all the files that contain it!
     
    roopajyothi, May 15, 2010 IP
  9. slimjim2010

    slimjim2010 Peon

    Messages:
    245
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9

    Good call!

    I think a text (.txt) file would work...
     
    Last edited: May 15, 2010
    slimjim2010, May 15, 2010 IP
  10. live.co.uk

    live.co.uk Banned

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    it's very easy
    just
    end the php by
    ?>
    adsense
    <?php
     
    live.co.uk, May 15, 2010 IP
  11. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #11
    No need for .txt file use .html file
    May cause some conflict in new browsers :)
     
    roopajyothi, May 15, 2010 IP