Re: Formatting

From: Date: Wed, 26 Jan 2011 06:16:12 +0000
Subject: Re: Formatting
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-311035@lists.php.net to get a copy of this message
On 1/25/2011 9:05 PM, Ethan Rosenberg wrote:
Dear list - I have a program with the following statement: $out = system('ls -l', $retval); The output is a string. How do I format the output to be in the Linux format, that is in columns. I cannot think of a way to use explode to do it. Advice and comments, please. Thanks Ethan MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)]
Well, depends, are you running this in a browser or at the console? If you are displaying this in a browser, you are probably seeing that browsers do not like \n (newlines) If in a browser, you could: 1) Wrap your output in a <pre><?php echo $out; ?></pre> HTML tag 2) Use PHP's nl2br() to replace all newlines with "<br />" tags 3) Use PHP's header() function to tell the browser to display the output as plaintext. i.e. header('Content-Type: text/plain'); [1,2] 1 - Google "php header plain text" 2 - http://www.php.net/manual/en/function.header.php#92620 If in cli... well, you wouldn't be having this problem... :) Jim Lucas

« previous php.general (#311035) next »