Last active
January 3, 2016 16:09
-
-
Save zzuhan/8487484 to your computer and use it in GitHub Desktop.
路径连接,可以输入无限制个参数,不用再担心`/`反斜线重复或者缺少。TODO:处理''.",'..'这种相对路径 这个php原生有realpath方法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function joinPaths() | |
{ | |
$args = func_get_args(); | |
$paths = array(); | |
foreach ($args as $arg) { | |
$paths = array_merge($paths, (array)$arg); | |
} | |
$paths = array_map(create_function('$p', 'return trim($p, "/");'), $paths); | |
if (substr($args[0], 0, 1) == '/') { | |
$paths[0] = '/' . $paths[0]; | |
}; | |
$paths = array_filter($paths); | |
return join('/', $paths); | |
} | |
joinPaths('/Users/wencheng', 'devspace', 'php'); // /Users/wencheng/devspace/php |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pubic |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment