Jump to content

ls arranged into a table


Stephen

Recommended Posts

$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

<?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>";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.