SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    183
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Inserting Javascript into PHP page

    I know nothing about PHP, what I am trying to do is insert the following standard Google Javascript code into my PHP page:

    Code:
    <script type="text/javascript"><!--
    google_ad_client = "";
    google_ad_width = 468;
    google_ad_height = 60;
    google_ad_format = "468x60_as";
    google_ad_type = "text_image";
    google_ad_channel ="";
    google_color_border = "FFFFFF";
    google_color_bg = "FFFFFF";
    google_color_link = "0000FF";
    google_color_url = "008000";
    google_color_text = "000000";
    //--></script>
    <script type="text/javascript"
      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    I want to display this at the bottom of this table that is being written using PHP. I thought I would create another row and then put the Google script in there.

    Code:
    echo "<!-- Start of main body table -->\n\n";
    
    echo "<table width=\"" . $CONFIG_VAR['body_width_value'] . "\" align=\"center\" cellspacing=\"0\" border=\"0\" cellpadding=\"0\" bgcolor=\"#" . $CONFIG_VAR['main_body_colour'] . "\">\n";
    echo "<tr>\n";
    
    
    // This creates the lefthand menu column
    include_template ( $CONFIG_VAR['left_column_template'] );
    
    // This creates the middle table
    echo "<!-- Start of middle column -->\n\n";
    echo "<td valign=\"top\">\n";
    
    
    if ( empty ( $offset ) ) 
        { 
        $offset = 0; 
        } 
    
    -- Whole bunch of code here and then..
    
       print_message ( $lang['review_message_1'], $lang['review_message_3'] );
        die;    
        }
    
    
    //This creates the main menu along the bottom of the main column
    bottom_menu( "yes" );
    
    echo "</td>\n";
    echo "<!-- End of middle column -->\n\n";
    How would I go about doing this?

    Thank you.

  2. #2
    SitePoint Evangelist dmsuperman's Avatar
    Join Date
    Feb 2005
    Location
    A box
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    ?><script type="text/javascript"><!--
    google_ad_client = "";
    google_ad_width = 468;
    google_ad_height = 60;
    google_ad_format = "468x60_as";
    google_ad_type = "text_image";
    google_ad_channel ="";
    google_color_border = "FFFFFF";
    google_color_bg = "FFFFFF";
    google_color_link = "0000FF";
    google_color_url = "008000";
    google_color_text = "000000";
    //--></script>
    <script type="text/javascript"
      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script><?PHP
    Just stick it where you want the ads to show up.
    <(^.^<) \(^.^\) (^.^) (/^.^)/ (>^.^)>
    Core 2 Duo E8400 clocked @ 3.375GHz, 2x2GB 800MHz DDR2 RAM
    5x SATA drives totalling 2.5TB, 7900GS KO, 6600GT

  3. #3
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, as dmsuperman said above, you can just exit out of PHP where you want to display the ads, then reented it after the JS is done.

  4. #4
    Non-Member melancholic's Avatar
    Join Date
    Nov 2004
    Location
    Australia
    Posts
    447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alternatively, you can use heredoc syntax...

    http://au.php.net/manual/en/language...syntax.heredoc

    PHP Code:
    echo <<<EOD
    <script type="text/javascript"><!--
    google_ad_client = "";
    google_ad_width = 468;
    google_ad_height = 60;
    google_ad_format = "468x60_as";
    google_ad_type = "text_image";
    google_ad_channel ="";
    google_color_border = "FFFFFF";
    google_color_bg = "FFFFFF";
    google_color_link = "0000FF";
    google_color_url = "008000";
    google_color_text = "000000";
    //--></script>
    <script type="text/javascript"
      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    EOD; 

  5. #5
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    183
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys. I tried the first one, and it ends up looking something like this. Not the Google ads on the top, but the one in the body of the review. As you can see it is bit off.

    http://www.triprater.com/review.php?..._id=3&offset=0

    Here is the code for where I dumped it in. How do I get it to align properly with the rest of the table?

    Code:
        // Start of the review text table
        echo "<table width=\"90%\" border=\"0\" align=\"center\">\n";
        echo "<tr>\n";
        echo "<td class=\"mnlreviewtext\">$review_text</td>\n";
    ?><script type="text/javascript"><!--
    google_ad_client = "";
    google_ad_width = 468;
    google_ad_height = 60;
    google_ad_format = "468x60_as";
    google_ad_type = "text_image";
    google_ad_channel ="";
    google_color_border = "FFFFFF";
    google_color_bg = "FFFFFF";
    google_color_link = "0000FF";
    google_color_url = "008000";
    google_color_text = "000000";
    //--></script>
    <script type="text/javascript"
      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script><?PHP
        echo "</tr>\n";
    
        echo "<tr>\n";
        echo "<tr><td height=\"5\">&nbsp;</td></tr>\n";

  6. #6
    SitePoint Wizard REMIYA's Avatar
    Join Date
    May 2005
    Posts
    1,351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or you can echo each line like this:

    PHP Code:
     echo '<script type="text/javascript"><!-- '
    echo 
    'google_ad_client = "";';
    echo 
    'google_ad_width = 468; ';
    echo 
    'google_ad_height = 60; ';
    etc... 
    Hope this helps


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •