faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

17 of 25 people (68%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How can I display the output of passthru or system with newline chars? i.e. passthru("ps ax")

Jan 26th, 2009 21:36
katie shein, healthy man, dman, Brian Coogan, Onno Benschop, Scott Graves, http://www.ttnr.org


I'm assuming you're finding that the text is coming out, but it's all 
squashed together.
This is because you are sending raw text in the middle of an HTML page.
You have three options:
1. Put a <pre> before and a </pre> after the output
2. Output the stuff as a text file, which you can achieve by sending a 
Header("Content-type: text/text") before any output.
3. Use nl2br() to convert the newlines to <br>, eg: nl2br(`ps ax`)
Using <pre> is probably simpler here for ps output, as ps relies on
output being in fixed width font so it appears in columns.  <pre> uses a
fixed width font so works well.
http://www.healthdothealth.com
http://www.healthxhealth.com
http://www.mesotheliomainmesothelioma.com
http://www.healthfirewall.com
http://www.flathealth.com
http://www.healthbodyguard.com
http://versicherungs101.blogspot.com
http://guiadeseguros.blogspot.com
http://verzekeringengids.blogspot.com
http://osiguranjevodic.blogspot.com
http://seguroguia.blogspot.com
http://ideide-cadouri.blogspot.com
http://gavoride.blogspot.com
http://donsideia.blogspot.com
http://ideeregalo1.blogspot.com
http://partideer.blogspot.com