我有这两个代码片段,我一直在玩,但似乎无法让逻辑坚持其中任何一个.
我试图看看给定的字符串是否在末尾有一个'/',如果没有,则添加它.
$path = '.';
if (substr($path, 0, -1) != '/')
$path .= '/';
Run Code Online (Sandbox Code Playgroud)
和
if (strrpos('/', $path) !== true)
$path .= '/';
Run Code Online (Sandbox Code Playgroud)
我所拥有的问题是,如果我$path等于'./那么我得到它作为输出.//
这是我遇到问题的片段
if (!is_array($paths))
$this->classPath[] = $paths;
else
$this->classPath = $paths;
foreach ($this->classPath as $path) {
if (strrpos('/', $path) !== true)// || substr_count($path, '/') >= 0)
$path = $path . '/';
//else
//$this->classPath[] = $path;
//echo '0';
$pathArr[] = $path;
Run Code Online (Sandbox Code Playgroud) php ×1