1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

HTML In PHP

Discussion in 'PHP' started by Crazy_Zap, Dec 23, 2007.

  1. #1
    I have the following code that is inserted into a Wordpress theme file.

    As you can imagine, it's not outputting correctly. I am no coder so I need some help with this. The following code should (hopefully) determine the country a visitor is from and display the appropriate banner to them.

    <?php
    $country = wp_ozh_getCountryName(0) ;
    switch ($country) {
       case "Canada" :
    <a target="_blank" href="http://www.affiliate.com/fs-bin/click?id=referrer_ID"><IMG alt="Canadian Banner" border="0" src="http://images.affiliate.com/outsidebanners/Homepage-120X600.gif"></a><IMG border="0" width="1" height="1" src="http://ad.affiliate.com/fs-bin/show?id=referrer_ID">;
            break;
       default :
    <a target="_blank" href="http://www.affiliate.com/fs-bin/click?id=referrer_ID"><IMG alt="American Banner" border="0" src="http://images.affiliate.com/outsidebanners/Homepage-120X600.gif"></a><IMG border="0" width="1" height="1" src="http://ad.affiliate.com/fs-bin/show?id=referrer_ID">;
    }
    ?>
    PHP:
    The code that determines the country is working fine when I substitute the html banner links with the echo command. I just need someone to tell me how to include the html code with the correct syntax inside the php tags.

    Thanks!
     
    Crazy_Zap, Dec 23, 2007 IP
  2. jmhyer123

    jmhyer123 Peon

    Messages:
    542
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try this

    
    <?php
    $country = wp_ozh_getCountryName(0) ;
    switch ($country) {
       case "Canada" :
    Print "<a target=\"_blank\" href=\"http://www.affiliate.com/fs-bin/click?id=referrer_ID\"><IMG alt=\"Canadian Banner\" border=\"0\" src=\"http://images.affiliate.com/outsidebanners/Homepage-120X600.gif\"></a><IMG border=\"0\" width=\"1\" height=\"1\" src=\"http://ad.affiliate.com/fs-bin/show?id=referrer_ID\">";
            break;
       default :
    Print "<a target=\"_blank\" href=\"http://www.affiliate.com/fs-bin/click?id=referrer_ID\"><IMG alt=\"American Banner\" border=\"0\" src=\"http://images.affiliate.com/outsidebanners/Homepage-120X600.gif\"></a><IMG border=\"0\" width=\"1\" height=\"1\" src=\"http://ad.affiliate.com/fs-bin/show?id=referrer_ID\">";
    }
    ?>
    
    PHP:
    That should work...
     
    jmhyer123, Dec 23, 2007 IP
    Crazy_Zap likes this.
  3. Crazy_Zap

    Crazy_Zap Well-Known Member

    Messages:
    1,342
    Likes Received:
    305
    Best Answers:
    0
    Trophy Points:
    170
    #3
    I'll try that. Thanks!
     
    Crazy_Zap, Dec 23, 2007 IP
  4. Arch3r25

    Arch3r25 Guest

    Messages:
    101
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yeah. You have to use print or echo to output the HTML strings.

    What jmhyer posted should work.
     
    Arch3r25, Dec 23, 2007 IP
    Crazy_Zap likes this.
  5. clinton

    clinton Well-Known Member

    Messages:
    2,166
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    110
    #5
    or to make things easier you could do this

    php code here
    {
    ?>
    html here
    <?php
    }
     
    clinton, Dec 23, 2007 IP
    Crazy_Zap likes this.
  6. kishore415

    kishore415 Well-Known Member

    Messages:
    1,462
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    160
    #6
    This will be the correct solution...for you

     
    kishore415, Dec 23, 2007 IP
    Crazy_Zap likes this.
  7. AYCOM

    AYCOM Peon

    Messages:
    33
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Definitely do it the way kishore415 said. When I was first learning PHP I used echo and print to insert HTML code and now I run into a lot of problems with trying to debug and work with all that old code.
     
    AYCOM, Dec 23, 2007 IP
    Crazy_Zap likes this.
  8. Crazy_Zap

    Crazy_Zap Well-Known Member

    Messages:
    1,342
    Likes Received:
    305
    Best Answers:
    0
    Trophy Points:
    170
    #8
    I went with Clinton's suggestion. It's working great!

    Thanks to everyone for their suggestions!
     
    Crazy_Zap, Dec 24, 2007 IP
    buffalo likes this.