Tuesday, April 21, 2009

PHP parse_url

PHP's parse_url is a handy little function that will parse a URL and return the various components in an associative array. For instance, consider the following code:
$url = "http://www.google.com/search?hl=en&q=php+rules&btnG=Search";
$parts = parse_url($url);
print_r($parts);

This would return:
Array
(
[scheme] => http
[host] => www.google.com
[path] => /search
[query] => hl=en&q=php+rules&btnG=Search
)

No comments:

Post a Comment