donglei2022 2011-09-07 20:30
浏览 39
已采纳

PHP,从绝对路径中查找相对路径的最简单方法

let's say i have an absolute path : /myproject/web/uploads/myfolder/myfile.jpg

i'm searching to determinate a relative path fom a part of the absolute path, like this:

<?php

echo relative_path('/myproject/web/uploads/myfolder/myfile.jpg', 'web/uploads');

// print "myfolder/myfile.jpg"
  • 写回答

2条回答 默认 最新

  • dqrdlqpo775594 2011-09-07 20:39
    关注

    If I understand, you just want the part from the absolute path that is after the given part:

    function relative_path($absolute, $part) {
        $pos = strpos($absolute, $part);
        return substr($absolute, $pos + strlen($part) + 1);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?