I had some struggle to properly output/format server outputs. I've always been a fan of automating stuff with bash, awk, etc. but need the browser to present the results and let the user interact. With C's printf you can easily get a nice terminal output like this:
column | column | column | column
But when echoing this to a browser with PHP you typically get:
column |column|column| column
column_different length |column|column| column
- that doesn't line up well. So you try to wrap it up in a html table, but what if the columns need to be of a different length? This is not easy
I found a very easy solution to this problem: wrap the whole output in <pre></pre> tags and it will retain the original (txt) command line output. Hours of structuring and styling.. how could I overlook this simple html tag?
Second interesting thing I discovered is PHP's system() command that outputs to the browser in real-time. For example a dotted progress bar could be simulated with:
while (TRUE) { system('echo .'); sleep(1); }.. imagine the line-by-line output of a long script with data that is gathered over the net- that is a very verbose way to communicate with the user, just if he/she was using the command line. Much more informative then a simple (although elegant) ajax loader (http://www.ajaxload.info/)
So just this quick post to share these tips if you're making apps based on backend unix power scripts.