【问题标题】:remove spaces with listing folders using glob()使用 glob() 删除带有列表文件夹的空格
【发布时间】:2015-09-13 09:19:01
【问题描述】:

我尝试使用 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>";
}

?>

现在我在基本名称之后得到了空格。我不想要这些空格,并且在尝试删除 basename 中的空格时需要帮助。

【问题讨论】:

    标签: php glob spaces


    【解决方案1】:

    那是因为你的PHP_EOL。当它被呈现为 HTML 时,它就变成了所谓的 whitespace,它只会显示为一个空格。删除它,你会很高兴。

    【讨论】:

      猜你喜欢
      • 2020-11-08
      • 2019-12-26
      • 1970-01-01
      • 2022-01-26
      • 1970-01-01
      • 2016-03-29
      • 2016-10-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多