note 27948 added to function.dirname
| From: | ludma at pochtamt dot ru | Date: | Fri, 27 Dec 2002 02:35:50 +0000 |
| Subject: | note 27948 added to function.dirname | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-41326@lists.php.net to get a copy of this message | ||
This function does a correct way to a directory on a server,
it does not recognize only such ways as
http://???/script.php?dir=/ok/index.php
function url_dir($url) {
if (preg_match('/(.*)\/([^\/\.?]+)$/i', $url)) {
$t_dir = preg_replace('/[^\/]$/', '\\0/', $url);
} else {
$t_dir = preg_replace(
array('/(https?:\/\/)?(\w+\.)?(\w+\.'
.'[a-z]{2,4})(.*)\/([^\/]*)$/','/[^\/]$/'),
array('\\1\\2\\3\\4','\\0/'), $url);
}
return $t_dir;
}
Test:
$dir = url_dir("http://www.roja.ru/path/?ok=1&r=1");
--
http://www.php.net/manual/en/function.dirname.php
http://master.php.net/manage/user-notes.php?action=edit+27948
http://master.php.net/manage/user-notes.php?action=delete+27948
http://master.php.net/manage/user-notes.php?action=reject+27948