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 2 of 2
  1. #1
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,380
    Thanks
    264
    Thanked 32 Times in 31 Posts

    getting referrer extention

    Your thoughts, it works in 4 lines of code.

    Can we shorten it, without regex?

    PHP Code:

    $testurl 
    strtolower($_SERVER['HTTP_REFERER']); 
     
    $arrayA explode("."$testurl); //break it up by .

    // just in case there is a sub domain, 
    then do a second array to clear that out and just leave ext in its own element
    $arrayB 
    explode("/"$arrayA[2]);  

    echo 
    $arrayB[0];  //ext result  com or whatever ext it is

    //if i want the . i can just do 

    echo ".".$arrayB[0]; 
    Last edited by durangod; 02-20-2013 at 03:05 AM.

  • #2
    Regular Coder Coastal Web's Avatar
    Join Date
    Oct 2004
    Posts
    225
    Thanks
    12
    Thanked 3 Times in 3 Posts
    Nice little challenge... without regex l couldn't come up with a shorter method.
    But here's a function that works quite well:
    PHP Code:
    function get_tld_from_url$url ){
        
    $tld '';
        
    $url_parts parse_url( (string) $url );
        if( 
    is_array$url_parts ) && isset( $url_parts'host' ] ) ){
            
    $host_parts explode'.'$url_parts'host' ] );
            if( 
    is_array$host_parts ) && count$host_parts ) > ){
                
    $tld array_pop$host_parts );
            }
        }

        return 
    $tld;
    }

    echo 
    get_tld_from_url$_SERVER['HTTP_REFERER'] ); 
    Need a way to drive traffic to your new site?
    ==> Check out HelpMyHits.com!

  • Users who have thanked Coastal Web for this post:

    durangod (02-20-2013)


  •  

    Posting Permissions

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