我在 ls 命令中使用 php 函数 shell_exec:
shell_exec('ls');
返回是:
index.php index.php~ ajaxF.php ajaxF.php~ ajaxL.php ajaxL.php~ ajax.php
我注意到每个文件之间都有一个空格,我试图更改它但失败了('A' 它只是一个随机字符,事实上我想添加一些 html):
preg_replace('/ /', "A", $output);
preg_replace('/<br>/', "A", $output);
preg_replace('/\n/', "A", $output);
如何用任何其他字符替换此空白区域? 这个的意思是为每一行添加html数据。
是否可以拆分数组中的每一行?
顺便说一下,我正在使用 ubuntu。
谢谢!
最佳答案
为什么不使用 glob('*')
,它会返回当前目录中的文件数组?然后您可以使用 implode() 并插入您想要的任何分隔符字符/文本。
关于php - 如何替换 shell_exec 返回的空白空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10590987/