note 29703 deleted from function.dirname by danbrown
| From: | danbrown@php.net | Date: | Sun, 20 Jul 2008 19:09:45 +0000 |
| Subject: | note 29703 deleted from function.dirname by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142278@lists.php.net to get a copy of this message | ||
Note Submitter: *~^-+=:[*_*]:=+-^~*
----
My name is Alex but you can call me WindEagle
my website is windeagle.tk
my email is az[at]windeagle.tk
jon at PLEASE DO NOT SPAM ME sdsc edu
here is a better version of your script
function PATH($DIR,$URL){
$DIR=preg_split("/[\/\\\]/",dirname($DIR));
$URL=preg_split("/[\/\\\]/",dirname($URL));
$cDIR = count($DIR);
$cURL = count($URL);
$min = min($cDIR, $cURL);
for($x=1;$x<=$min;$x++){
if($DIR[$cDIR-$x]==$URL[$cURL-$x]){ // path matches
unset($DIR[$cDIR-$x],$URL[$cURL-$x]); // erase any common elements
}else{break;}} // all that's left is uncommon elements
// just incase $DIR or $URL equals "//"
$DIR = ereg_replace("//","/",join('/',$DIR)."/");
$URL = ereg_replace("//","/",join('/',$URL)."/");
return array("DIR" => $DIR,"URL" => $URL);}
example:
lets say that
for Win32
$_SERVER['SCRIPT_FILENAME']="C:\web\path\cgi-bin\script.php"
for Unix
$_SERVER['SCRIPT_FILENAME']="/web/path/cgi-bin/script.php"
$_SERVER['SCRIPT_NAME']="/~sn/cgi-bin/script.php"
PATH($_SERVER['SCRIPT_FILENAME'],$_SERVER['SCRIPT_NAME'])
return:
Array
(
for Win32
[DIR] => C:/web/path/
for Unix
[DIR] => /web/path/
[URL] => /~sn/
)