Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-20-2013, 02:58 AM   PM User | #1
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,191
Thanks: 217
Thanked 31 Times in 30 Posts
durangod is on a distinguished road
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..
durangod is offline   Reply With Quote
Old 02-20-2013, 03:15 AM   PM User | #2
Coastal Web
Regular Coder

 
Coastal Web's Avatar
 
Join Date: Oct 2004
Posts: 225
Thanks: 12
Thanked 3 Times in 3 Posts
Coastal Web is an unknown quantity at this point
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!
Coastal Web is offline   Reply With Quote
Users who have thanked Coastal Web for this post:
durangod (02-20-2013)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:39 PM.


Advertisement
Log in to turn off these ads.