note 14531 added to function.dirname.php
| From: | holtt at nacse dot org | Date: | Thu, 02 Aug 2001 21:09:42 +0000 |
| Subject: | note 14531 added to function.dirname.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-16247@lists.php.net to get a copy of this message | ||
I had some problems with dirname() not properly parsing some URLS, translating for example...
"http://www.xyz.com" to "http:"
and
"http://www.xyz.com/~someuser" to
"http://www.xyz.com"
To fix, I do something like this...
$temp_dir = dirname($doc->url);
$temp_base = basename($doc->url);
$base_url = $temp_dir;
if (preg_match ("/^~[a-zA-Z0-9\-\_]*$/", $temp_base)) {
$base_url = $temp_dir . "/" . $temp_base;
}
if ($temp_dir == "http:") {
$base_url = $temp_dir . "//" . $temp_base;
}
http://www.php.net/manual/en/function.dirname.php