[英]remove spaces with listing folders using glob()
I tried to list folders of a directory with the glob()
function of PHP. 我试图用PHP的
glob()
函数列出目录的文件夹。 I also used str_replace
. 我还使用了
str_replace
。
This is my code - 这是我的代码-
<?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>";
}
?>
Now I get spaces after the basename. 现在,我在基名之后得到空格。 I don't want the spaces and need help with trying to remove the spaces in basename.
我不需要空格,因此需要尝试删除基名中的空格的帮助。
That's because of your PHP_EOL
. 那是因为您的
PHP_EOL
。 When it's rendered as HTML it becomes what's known as a whitespace which will simply appear as a space. 当将其呈现为HTML时,它将成为所谓的空格 ,它将简单地显示为空格。 Remove it and you'll be happy.
删除它,您会很高兴的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.