The Parse_URL function can dice a URL into individual segments for later usage.
Suppose you’ve just parsed a group of RSS feeds, and you’re looping through the results, displaying the ten most recent. You would like to put the items’ source domains under the headlines. You decide the best way to go about it is to take each item’s permalink or guid value and strip everything out of the URL but the domain.
Here’s an example of how to do that with Parse_URL:
$the_permalink = "http://www.webmaster-source.com/2009/03/21/blogbuzz-march-21-2009/";
$the_domain = parse_url($the_permalink, PHP_URL_HOST);
echo $the_domain;
The script should output www.webmaster-source.com
. If you don’t pass the second argument, the function will return an associative array of all of the parts of the URL.