Bagata
Bagata

Reputation: 2170

How can I replace empty space from shell_exec return?

I'm using php function shell_exec with the ls command:

shell_exec('ls');

The return is:

index.php index.php~ ajaxF.php ajaxF.php~ ajaxL.php ajaxL.php~ ajax.php

I noticed a space between every file and I tried to change it but it fail ('A' it's just a random character, in fact I want to add some html):

preg_replace('/ /', "A", $output);
preg_replace('/<br>/', "A", $output);
preg_replace('/\n/', "A", $output);

How can I replace this empty space by any other character? The meaning of this is to add html data for every line.

Is it possible to split every line in an array?

By the way, I'm using ubuntu.

Thanks!

Upvotes: 0

Views: 220

Answers (1)

Marc B
Marc B

Reputation: 360782

Why not use glob('*'), which'll return an array of files in the current directory? Then you can use implode() and insert any separator char/text you want.

ref: http://php.net/glob http://php.net/implode

Upvotes: 5

Related Questions