Page 1 of 1

Adding BR tags to system(), exec(), and so on....

Posted: Mon Mar 19, 2007 5:06 pm
by Dirge of Cerberus
System, exec, popen, and other such commands are enabled on my server. I want to utilize them for compression and copying, but there's a problem.

I need to display output in a readable manner. However, no matter what I do, preg_replace nor nl2br will fix the linebreaks.

Code: Select all

<?PHP

$ls = system("ls");

$ls = nl2br($ls);

print $ls."<P> Test Run.";

?>
That script outputs this:

Code: Select all

adm cache common.php config.php cron.php docs download.php faq.php files images includes index.php install language ls.php mcp.php memberlist.php posting.php report.php search.php store style.php styles ucp.php viewforum.php viewonline.php viewtopic.php viewtopic.php

Test Run.
And the source is:

Code: Select all

adm
cache
common.php
config.php
cron.php
docs
download.php
faq.php
files
images
includes
index.php
install
language
ls.php
mcp.php
memberlist.php
posting.php
report.php
search.php
store
style.php
styles
ucp.php
viewforum.php
viewonline.php
viewtopic.php
viewtopic.php<P> Test Run.
How do I add BR?

Posted: Mon Mar 19, 2007 5:46 pm
by volka
http://de2.php.net/system wrote:system — Execute an external program and display the output
try

Code: Select all

echo '<pre>';
system("ls"); 
echo '</pre>';
or

Code: Select all

exec ("ls", $ls);

echo 'test run. ', nl2br($ls);