Closed Thread
Results 1 to 5 of 5




  

Thread: HTML Within PHP

      
  1. #1
    Zap
    Zap is offline
    I Love Lesbians! Zap has a reputation beyond reputeZap has a reputation beyond reputeZap has a reputation beyond reputeZap has a reputation beyond reputeZap has a reputation beyond reputeZap has a reputation beyond reputeZap has a reputation beyond reputeZap has a reputation beyond reputeZap has a reputation beyond reputeZap has a reputation beyond reputeZap has a reputation beyond repute Zap's Avatar
    Join Date
    September 29, 2006
    Location
    Canada, Eh?
    Posts
    4,385
    Rep Power
    10
    Feedback Score
    0

    Question HTML Within PHP

    I have the following code that is inserted into a Wordpress theme file. It's pretty slick! It guesses at the visitor's country, based on a database of IP addresses.

    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 Code:
    <?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">;
    }
    ?>
    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!
    Toronto Forum ♫ ♫ ♫ ♫ ♫ ♫ ♫ ♫ ♫ ♫ ♫ GET FREE EXPOSURE FOR YOUR BLOG!

  2. #2
    Jedi Master Cyberbite is a jewel in the roughCyberbite is a jewel in the roughCyberbite is a jewel in the roughCyberbite is a jewel in the roughCyberbite is a jewel in the roughCyberbite is a jewel in the rough Cyberbite's Avatar
    Join Date
    October 8, 2007
    Location
    Quincy, MA
    Posts
    362
    Rep Power
    5
    Feedback Score
    0

    Default

    Try this

    Code:
     <?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">; 
    <?
    } 
    ?> 
    When you have more that can be quickly printed or echoed, switch back and forth between code mode and html mode <? ?>. It makes it so much easier to read.


    Cyberbite added 1 Minutes and 54 Seconds later...

    And if you need to get a variable into the HTML you can do this

    Code:
    <?
    //code
    ?>
    <a href="http://blah><?=$variable?></a>
    <?
    //code
    ?>
    See the <?=$variable?>, use that to echo php code into html.
    Last edited by Cyberbite; Dec 23rd, 2007 at 8:05 pm. Reason: Automerged Doublepost
    BeanTown Host- Web Hosting, Dedicated Servers, Boston Colocation and Domain Names
    CPanel,RVSkins,Fantastico,RVSiteBuilder on all accounts.
    SysAdmin Valley - a sysadmin's ramblings, tips and tricks
    Cisco Sphere - Forum for Cisco users

  3. #3
    Zap
    Zap is offline
    I Love Lesbians! Zap has a reputation beyond reputeZap has a reputation beyond reputeZap has a reputation beyond reputeZap has a reputation beyond reputeZap has a reputation beyond reputeZap has a reputation beyond reputeZap has a reputation beyond reputeZap has a reputation beyond reputeZap has a reputation beyond reputeZap has a reputation beyond reputeZap has a reputation beyond repute Zap's Avatar
    Join Date
    September 29, 2006
    Location
    Canada, Eh?
    Posts
    4,385
    Rep Power
    10
    Feedback Score
    0

    Default

    Thanks Dude!


    Worked like a charm!
    Toronto Forum ♫ ♫ ♫ ♫ ♫ ♫ ♫ ♫ ♫ ♫ ♫ GET FREE EXPOSURE FOR YOUR BLOG!

  4. #4
    I'm New! jronmo is on a distinguished road
    Join Date
    December 27, 2007
    Posts
    2
    Rep Power
    0
    Feedback Score
    0

    Default

    PHP is not the prettiest looking language but its the easiest I've ever used. Typically I follow Cyberbyte's logic, but if you ever do go the other way, get a good PHP IDE that show's you where you have errors, or you will be looking for a missing backslash all day.

  5. #5
    Idolized By All noppid is just really nicenoppid is just really nicenoppid is just really nicenoppid is just really nicenoppid is just really nicenoppid is just really nicenoppid is just really nice noppid's Avatar
    Join Date
    October 12, 2006
    Location
    Florida
    Posts
    487
    Rep Power
    6
    Feedback Score
    0

    Default

    The caveat of the above code is that it uses short tags and IIRC the <?=$foo?> is also being deprecated.

    You should always use long tags <?php and use a full echo <?php echo $foo; ?> to be sure your code won't break in the near future.

    It's easy house keeping to avoid house cleaning in the future.

    Quote Originally Posted by jronmo View Post
    PHP is not the prettiest looking language but its the easiest I've ever used. Typically I follow Cyberbyte's logic, but if you ever do go the other way, get a good PHP IDE that show's you where you have errors, or you will be looking for a missing backslash all day.
    Use error_reporting() properly and your scripts will tell you everything that is wrong from your server without an IDE.
    Free vBulletin hacks and vBulletin Support.
    Talk to bikers around the world about motorcycles.
    Clogging an american dance step.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Do You Use An HTML Editor?
    By Ohiosweetheart in forum General Business
    Replies: 48
    Last Post: Apr 13th, 2011, 4:08 am
  2. Using Both home.html and index.html
    By zxpro168 in forum SEO Forum
    Replies: 14
    Last Post: Jun 10th, 2008, 6:47 am
  3. Using pure HTML, possible?
    By GameOver in forum General Business
    Replies: 6
    Last Post: May 8th, 2008, 10:29 am
  4. about html
    By raju in forum HTML & Website Design
    Replies: 2
    Last Post: Dec 4th, 2007, 10:09 pm

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
WebTalkForums
WebTalkForums
Recent Forum Threads