Show text based on domain name's first letter

Discussion in 'PHP' started by Paintball Guns, Jun 10, 2008.

  1. #1
    I need to display some text based on the first letter of a domain name.

    EXAMPLE:

    If the first letter in the domain name is A, echo "The first letter is A."
    If the first letter in the domain name is B, echo "The first letter is B."
    If the first letter in the domain name is C, echo "The first letter is C."
    If the first letter in the domain name is D, echo "The first letter is D."

    RESULT: If the code is run on...

    apple.com/ the page would display, "The first letter is A."
    banana.org/fruit/yellow.html the page would display, "The first letter is B."
    coffee.info/ the page would display, "The first letter is C."
    drink.com/pepsi/ the page would display, "The first letter is D."

    This script will be run on many domains that point to the same folder (the folder where this script is located).

    Code examples would be very appreciated!
     
    Paintball Guns, Jun 10, 2008 IP
  2. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #2
    
    <?php
    $domainName=$_SERVER["SERVER_NAME"];
    $firstLetter=substr($domainName,"0","1");
    echo "First letter is ".$firstLetter;
    ?>
    
    PHP:
    :)
     
    rohan_shenoy, Jun 10, 2008 IP
    Paintball Guns likes this.
  3. Paintball Guns

    Paintball Guns Active Member

    Messages:
    173
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Brilliant! It works perfectly. Thank you! Reputation added.
     
    Paintball Guns, Jun 10, 2008 IP
  4. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Welcome :)
     
    rohan_shenoy, Jun 11, 2008 IP