php路径转换的方法:1、通过“function sub_rel2abs(string $in_rel, string &$out_abs)”方法将相对路径转换成绝对路径;2、使用“abs2rel”方法将绝对路径转换成相对路径。

推荐:《PHP视频教程》
PHP 相对路径转换为绝对路径 realpath
* 相对路径 -> 绝对路径 realpath
relative path
$c_abs = realpath($ss_rel);
if ($c_abs === false) {
$i_rtn = -1;
} else {
$ss_rel = $c_abs;
$i_rtn = 0;
}
$lpc++;
} // while (count($sv_path)>0)
// normal ending
if (0===$i_rtn) {
$out_abs = $ss_rel; // set converted path
}
return $i_rtn;
}
// test
$inDir = "/Users/Mch/Code/php/Directory";
is_dir($inDir) || mkdir($inDir, 0777, true);
$wd = __DIR__;
chdir($inDir);
$out = "";
echo sub_rel2abs("../../../eclipse-workspace/blog.zip", $out).PHP_EOL;
echo $out.PHP_EOL;
chdir($wd);
@rmdir($inDir);output:
立即学习“PHP免费学习笔记(深入)”;
采用 php+mysql 数据库方式运行的强大网上商店系统,执行效率高速度快,支持多语言,模板和代码分离,轻松创建属于自己的个性化用户界面 v3.5更新: 1).进一步静态化了活动商品. 2).提供了一些重要UFT-8转换文件 3).修复了除了网银在线支付其它支付显示错误的问题. 4).修改了LOGO广告管理,增加LOGO链接后主页LOGO路径错误的问题 5).修改了公告无法发布的问题,可能是打压
/Users/Mch/eclipse-workspace/blog.zip
这里直接realpath就可以了,为什么多此一举?
* 绝对路径 -> 相对路径
= count($a) || $j >= count($b)) {
throw new Exception('$j out of range');
}
for ($i = $j; $i >= 0; $i--) {
if (strcmp($b[$i], $a[$i])!==0) {
return false;
}
}
return true;
};
// 找到a,b数组元素相同的下标
while (array_pop($a)) {
$i = count($a)-1;
if (isset($b[$i])) {
if ($sliceEquals($a, $b, $i)) {
break;
}
}
array_push($d, "..");
}
// 从首个不同元素开始
for ($i+=1; $i < count($b); $i++) {
array_push($d, $b[$i]);
}
return ".".DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $d);
}










