美文网首页
php求相对路径

php求相对路径

作者: ZoneWonderful | 来源:发表于2017-11-27 08:55 被阅读0次

求相对路径

function test (){
            //求b相对a的路径
            $a="D:\work_software\phpstudy\WWW\JingShTest\app\protected\modules\accounts\controllers\DefaultController.php";
            $b="D:\work_software\phpstudy\WWW\JingShTest\SMS.php";
            $len=strlen($a);
            $relatePath='';
            $count=0;
            $slash=0;
            for($i=0;$i<$len;$i++)
            {
                $c1=substr($a,$i,1);
                $c2=substr($b,$i,1);
                if($c1==$c2)
                {
                    $count++;
                    if($c1=="\\")
                        $slash++;
                    continue;
                }
                else
                {
                    break;
                }
            }

            for($j=0;$j<$slash;$j++)
            {
                $relatePath.="..\\";
            }
            $relatePath.=substr($b,$count);
            return $relatePath;
        }

相关文章

网友评论

      本文标题:php求相对路径

      本文链接:https://www.haomeiwen.com/subject/tombsxtx.html