note 87837 deleted from function.parse-url by danbrown
| From: | danbrown@php.net | Date: | Fri, 26 Dec 2008 16:38:16 +0000 |
| Subject: | note 87837 deleted from function.parse-url by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-148535@lists.php.net to get a copy of this message | ||
Note Submitter: jaundice at yahoo dot com
----
I noticed the parse_url function basically fails big time when you don't have a scheme.
$str='www.cow.com?thisworks=false';
$array=parse_url($str);
(
[path] => www.cow.com
[query] => thisworks=false
)
So, it assumes the input is a relative url if it doesn't have a scheme. However, this is not
what I want - while all the URLs I'm processing are not local, they may or may not have http://. I could first check for that with strpos and append if necessary, but
why not have a function that just works regardless?
The ones provided below (parseUrl) work just right, with or without a scheme. Thanks!
php > print_r($array);
Array
(
[0] => www.cow.com?thisworks=true
[scheme] =>
[1] =>
[login] =>
[2] =>
[pass] =>
[3] =>
[host] => www.cow.com
[4] => www.cow.com
[subdomain] => www
[5] => www
[domain] => cow.com
[6] => cow.com
[extension] => com
[7] => com
[port] =>
[8] =>
[path] =>
[9] =>
[file] =>
[10] =>
[arg] => thisworks=false
[11] => thisworks=false
)