note 24111 deleted from function.parse-url by didou
| From: | didou@php.net | Date: | Thu, 09 Oct 2003 13:29:26 +0000 |
| Subject: | note 24111 deleted from function.parse-url by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-58130@lists.php.net to get a copy of this message | ||
Note Submitter: wea@agin.com
----
I needed a script to flesh out a truncated URL provided through a form, such as foobar.com or
www.foobar.com.
With the truncated forms, parse_url seems to treat the domain name as part of the path. The below
script works around this.
function correct_url ($url)
{
If ($url==FALSE) {
return $url;
}
$url=parse_url($url);
If (stristr($url['host'], "www")==FALSE and $url['scheme']==FALSE and
stristr($url['path'], "www")==FALSE) {
$url['host']="www." .$url['host'];
}
$new_url="http:" .$url['port'] ."//"
.$url['host'] .$url['path'];
If ($url['query']!=FALSE) {
$new_url=$new_url ."?" .$url['query'];
}
If ($url['fragment']!=FALSE) {
$new_url=$new_url ."#" .$url['fragment'];
}
return $new_url;
}