Skip to content

Instantly share code, notes, and snippets.

@zzuhan
Created March 12, 2014 08:18
Show Gist options
  • Save zzuhan/9502860 to your computer and use it in GitHub Desktop.
Save zzuhan/9502860 to your computer and use it in GitHub Desktop.
测算相对路径,摘自php.net网友贡献
function relative($from, $to, $ps=DIRECTORY_SEPARATOR){
$arFrom = explode($ps, rtrim($from, $ps));
$arTo = explode($ps, rtrim($to, $ps));
while(count($arFrom) && count($arTo) && ($arFrom[0] == $arTo[0]))
{
array_shift($arFrom);
array_shift($arTo);
}
return str_pad("", count($arFrom) * 3, '..'.$ps).implode($ps, $arTo);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment