[英]remove spaces with listing folders using glob()
我试图用PHP的glob()
函数列出目录的文件夹。 我还使用了str_replace
。
这是我的代码-
<?php
/* files directory (strukture):
*files
* folder_01
* folder_02
* test.png
* test.txt
* folder_03
*/
$file_dir = "files";
foreach(glob($file_dir.'/*', GLOB_ONLYDIR) as $dir) {
$dir = str_replace($file_dir.'/','',$dir);
echo basename($dir).PHP_EOL./*why is between the basename and the following text a space?*/">>some text<<"."<br>";
}
?>
现在,我在基名之后得到空格。 我不需要空格,因此需要尝试删除基名中的空格的帮助。
那是因为您的PHP_EOL
。 当将其呈现为HTML时,它将成为所谓的空格 ,它将简单地显示为空格。 删除它,您会很高兴的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.