【问题标题】:How to compare 2 different string that link to 1 directory?如何比较链接到 1 个目录的 2 个不同字符串?
【发布时间】:2011-02-05 10:11:37
【问题描述】:

例如,接下来的 2 个 var 提供了指向同一目录的链接,但字符串不同。
我如何检测它们是否意味着相同的目录?

$dir1 = 'application/somedir/some_subdir/../';
$dir2 = 'application/somedir/';

【问题讨论】:

    标签: php filepath


    【解决方案1】:

    使用realpath()

    if (realpath($dir1) == realpath($dir2)) {
        do_stuff();
    }
    

    http://php.net/manual/en/function.realpath.php

    您可能还想在使用之前检查目录是否存在。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-23
      相关资源
      最近更新 更多