PHP Parse_URL()

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 = "";
$the_domain = parse_url($the_permalink, PHP_URL_HOST);
echo $the_domain;

The script should output If you don’t pass the second argument, the function will return an associative array of all of the parts of the URL.