Stephen Posted June 9, 2009 Share Posted June 9, 2009 $ars["shell"]["exec"] = `ls -aFhl --group-directories-first ./`; echo($ars["shell"]["exec"]); Outputs: total 80K drwxr-xr-x 4 stephen root 4.0K 2009-06-08 20:39 ./ drwxr-xr-x 20 stephen root 4.0K 2008-09-24 08:16 ../ drwxr-xr-x 2 stephen root 4.0K 2009-01-04 19:15 webalizer/ drwxr-xr-x 7 stephen root 4.0K 2009-01-04 19:15 xampp/ -rw-r--r-- 1 stephen stephen 105 2009-06-08 21:22 ars.php -rw-r--r-- 1 stephen root 31K 2007-05-11 08:40 favicon.ico -rw-rw-rw- 1 stephen root 163 2003-10-31 16:15 index.html -rw-r--r-- 1 stephen stephen 12K 2008-12-07 16:19 index.php -rw-r--r-- 1 stephen stephen 1.8K 2009-01-04 19:12 layout.html -rw-r--r-- 1 stephen stephen 7.7K 2008-12-07 16:06 rsc.php Is there anyway to arrange the output of the command into a table with separate columns, such as permissions, links, owner, group, size, last edited, and file name. Link to comment https://forums.phpfreaks.com/topic/161456-ls-arranged-into-a-table/ Share on other sites More sharing options...
gevans Posted June 9, 2009 Share Posted June 9, 2009 <?php $rows = explode("\n", $ars["shell"]["exec"]); echo $rows[0]; echo "<table>\n"; echo "<tr>\n<td>permissions</td><td>links</td><td>owner</td><td>group</td><td>size</td><td>last edited date</td><td>last edited time</td><td>file name</td>\n</tr>\n"; for($i=1; $i<count($rows);$i++) { $data_chunks = explode(" ", $rows[$i]); echo "<tr>\n"; foreach($data_chunks as $chunks) { if(empty($chunks)) continue; echo "<td>$chunks</td>\n"; } echo "</tr>\n"; } echo "</table>"; Link to comment https://forums.phpfreaks.com/topic/161456-ls-arranged-into-a-table/#findComment-852024 Share on other sites More sharing options...
Stephen Posted June 9, 2009 Author Share Posted June 9, 2009 Ah, thanks. I didn't think of just skipping over the excess spaces D: However, there is one problem: if the file name contains a space in it, it starts a new row. I suppose this could be solved by doing file names separate. Link to comment https://forums.phpfreaks.com/topic/161456-ls-arranged-into-a-table/#findComment-852030 Share on other sites More sharing options...
gevans Posted June 9, 2009 Share Posted June 9, 2009 I suppose this could be solved by doing file names separate. Did you mean the actual persons name? Did you need more help? I get confused very easily Link to comment https://forums.phpfreaks.com/topic/161456-ls-arranged-into-a-table/#findComment-852146 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.