0

Say I have a badly formatted path /public/var/www/html/images\uploads\

Are there any performance benefits between these two methods to "normalize" the slashes, or is it just a different way of doing things?

  1. realpath($path) . DIRECTORY_SEPARATOR
  2. str_replace('\\', '/', $path);
4

1 回答 1

0

realpath() 可能并且可能确实需要更多的计算,但它比 str_replace() 做的更多。至于您将使用哪个取决于您并且取决于应用程序。realpath() 不仅会修复字符串的格式。而且还会验证该名称存在的文件。此外,在大多数情况下,使用 realpath() 将使您的代码更具可读性和更易于理解,因为它的命名更好地对应于它的功能(再次取决于应用程序)。

真实路径()

于 2017-08-24T23:41:27.983 回答