I have written two extremely useful functions for my
CMS that I think could be useful for other people.
---------------------------------------------------
Code:
function compare_paths($coma, $comb)
{
//===== We want the directory ================
$temp = explode("/", $coma);
$temp = array_reverse($temp);
if(substr_count($temp[0], "."))
{
array_shift($temp);
$temp = array_reverse($temp);
$coma = implode("/", $temp);
}
else
{
//----- No trailing slash -------------------
if($coma{strlen($coma) - 1} == "/")
{
$coma = substr($coma, 0, strlen($coma) - 1);
}
}
$temp = explode("/", $comb);
$temp = array_reverse($temp);
if(substr_count($temp[0], "."))
{
array_shift($temp);
$temp = array_reverse($temp);
$comb = implode("/", $temp);
}
else
{
//----- No trailing slash -------------------
if($comb{strlen($comb) - 1} == "/")
{
$comb = substr($comb, 0, strlen($comb) - 1);
}
}
//===== No starting slashes ==================
if($coma{0} == "/")
{
$coma = substr($coma, 1, strlen($coma) - 1);
}
if($comb{0} == "/")
{
$comb = substr($comb, 1, strlen($comb) - 1);
}
//===== Remove same start ====================
for($a = strlen($coma);$a > 0;$a--)
{
$b = substr($coma, 0, $a);
if(substr_count($comb, $b))
{
$coma = str_replace($b, "", $coma);
$comb = str_replace($b, "", $comb);
break;
}
}
//===== Add dots =============================
if(strlen($comb))
{
for($a = 0;$a < count(explode("/", $comb));$a++) { $coma = "../".$coma; }
}
else
{
$coma = ".".$coma;
}
//===== And we are done! =====================
return $coma;
}
This function makes $coma relative to $comb.
E.g.
Would return:
---------------------------------------------------
This function finds the difference between two timezones.
E.g.
Would return something like:
Quote:
Server Timezone: 800
Client Timezone: 930
Server: 11:02 PM
GMT: 3:02 PM
Client: 12:32 AM
Client: 12:32 AM
|