Possible Duplicate:
Getting domain name without TLD
So I have a Web site I am trying to work on. In the URL there is info and I want to parse it out and use it to make a db call to mysql:
http://www.relevant-info.org/home.html
I want to take the Url put it into a string.
Then I want to only get ‘relevant-info’ out of the url.
$webaddress = $_SERVER["SERVER_NAME"];
$parts = parse_url($webaddress);
$url = substr($Parts, 4, -4);
^ i am using that and I got the ip address (it is a centos 5.8 lamp) on a VM i am testing this, so in short this seams to work good so far 🙂
Credits to Relentless
You can easily find it with the PHP parse-url function: parse_url
Example usage: If you want to get ‘relevant-info’, a PHP 5.4 valid code could look like:
Output
For PHP 5.3 and less
In future situtations, if you do not have fancy functions like parse-url, you can use Regex or use str_split
Remember that str_split requires less resources