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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Dirge of Cerberus
Forum Commoner
Posts: 38
Joined: Mon Nov 20, 2006 9:01 pm

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

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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);
Post Reply