note 24111 added to function.parse-url
| From: | wea at agin dot com | Date: | Tue, 06 Aug 2002 23:23:31 +0000 |
| Subject: | note 24111 added to function.parse-url | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-34435@lists.php.net to get a copy of this message | ||
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;
}
--
http://www.php.net/manual/en/function.parse-url.php
http://master.php.net/manage/user-notes.php?action=edit+24111
http://master.php.net/manage/user-notes.php?action=delete+24111
http://master.php.net/manage/user-notes.php?action=reject+24111