Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Sep 2004
    Posts
    713
    Thanks
    6
    Thanked 2 Times in 2 Posts

    how to find our the extention of a domain name

    hi
    how do you find out the extention of a domain name?
    thanks
    flying dagger

  • #2
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    PHP Code:
    preg_match('/.*\.(.*)/''del.icio.us'$tld);
    echo 
    $tld[1]; // us 
    Is this what you mean?

  • #3
    Regular Coder
    Join Date
    Sep 2004
    Posts
    713
    Thanks
    6
    Thanked 2 Times in 2 Posts
    what i want is actually for example
    yayaya.com
    i want to find out its extention is .com not .net or .org
    flying dagger

  • #4
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    edit for a better regex that matches things like co.uk (still kinda flawed)
    PHP Code:
    $domain 'www.example.com';
    preg_match('/\.([a-zA-Z]{2,3}\.[a-zA-Z]{2}|[a-zA-Z]{2,4})$/'$domain$tld);
    print_r($tld); 
    Last edited by ralph l mayo; 01-11-2006 at 12:38 AM.

  • #5
    Regular Coder
    Join Date
    Sep 2004
    Posts
    713
    Thanks
    6
    Thanked 2 Times in 2 Posts
    well, how to build a function to check com,net,org,us,info,cc,com.sg?
    flying dagger

  • #6
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php
    function get_tld($url) {
         
    $url parse_url($url);
         return 
    substr($url['host'], strripos($url['host'], '.') + 1);
    }
    echo 
    get_tld('http://foo.com/bar.php?foobar=barfoo'); // Returns 'com' (without quotes).
    ?>
    "$question = ( to() ) ? be() : ~be();"

  • #7
    Regular Coder Element's Avatar
    Join Date
    Jul 2004
    Location
    Lynnwood, Washington, US
    Posts
    855
    Thanks
    2
    Thanked 2 Times in 2 Posts
    In addition to your problem, using Velox's code...


    PHP Code:
    <?php 
    function valid_tld($url) {
         
    $valid_tld = array('com''net''org'); // Valid TLDs 
         
    $url parse_url($url); // URL parts
         
    $tld substr($url['host'], strripos($url['host'], '.') + 1); // TLD 
         
    if(in_array($tld$valid_tld)) { return true; } else { return false; }


    if(
    valid_tld("http://example.com/index.php?a=a&b=b")) {
      echo 
    "Valid domain!";
    }

    ?>


  •  

    Posting Permissions

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