2012-05-14 66 views
0

我使用PHP函数用了shell_exec ls命令:如何从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。

谢谢!

回答

5

为什么不使用glob('*'),它会返回当前目录中的文件数组?然后你可以使用implode()并插入你想要的任何分隔字符/文本。

裁判:http://php.net/globhttp://php.net/implode

+0

谢谢!比我期待的更好! – Bagata