Forum Moderators: coopster
Example:
Say the domain is [cnet.com...]
I need this to return the variable with "cnet.com"
Say the domain is [reviews.cnet.com...]
I need this to return the variable with "cnet.com"
So basically I am passing the parameter of the long string of the domain and want returned the "site.com" or "site.net" domain name (without anything else).
Thanks in advance.
<?php
$url = 'http://www.webmasterworld.com/stuffs/anyfile.php';
print_r(parse_url($url));
echo parse_url($url, PHP_URL_PATH);
?>
another way would be to use a regex
but this could get complicated due to multiple ways of forming an URL
[sitepoint.com...]
========================================================
Hey,
I want to track all the domains that refer visitors to my site.
ut thing is I don't want for example, both [google.com...] and [google.com...] in my mysql database.
I just want google.com
What would be the best way to do this?
I don't need the subpage but the subdomain yes.
For example video.google.com and google.com being 2 different referrals.
My question is how I convert the referral into the (sub)domain?
Few ways I've found so far, but I don't know witch one is the best/most reliable:
Using preg_match:
PHP Code:
<?php
$url = "http://www.website.com";
preg_match("/^(http:\/\/)?([^\/]+)/i" , $url, $found);
preg_match("/[^\.\/]+\.[^\.\/]+$/" , $found[2], $found);
echo "domain found: ".$found[0]."<br />";
?>