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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.