如果我的网站存储在服务器上这样的地方:
/home/usr1/public_html/
其中映射到:
http://example.com/
但后来我在这个网址的文件中:
http://example.com/section1/page1.php
我想包含一个保存在以下位置的文件:
/home/usr1/public_html/includes/common.php
PHP 中是否有一个简单的函数可以用来将一个路径与另一个路径(例如当前路径)进行比较,以获取从另一个路径获取所需的相对字符串?
例如:
$thisPath = dirname(__FILE__);
// $thisPath is now equal to:
// /home/usr1/public_html/section1/page1.php
$relPath = comparePaths($thisPath, '/home/usr1/public_html/includes/common.php');
// $relPath is now equal to:
// ../includes/common.php
$relPath2 = comparePaths($thisPath, '/home/usr1/public_html/section1/part2/anotherpage.php');
// $relPath2 is now equal to:
// part2/anotherpage.php
是否存在这样的特征或功能(或类似的)?
阿晨1998
侃侃无极