LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to conserver spacings from shell to php (https://www.linuxquestions.org/questions/programming-9/how-to-conserver-spacings-from-shell-to-php-392095/)

ALInux 12-12-2005 06:27 PM

How to conserver spacings from shell to php
 
Hi I want to display the output of the command top in a list .......the user chooses an option from the list and kills the corresponding process (never mind about security ...it is a private project).
The output of my command prints neatly as follows in php when I use echo $reply,

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2264 root 16 0 111m 60m 4124 R 25.3 24.3 29:54.20 X
2756 ali 12 0 62556 58m 19m R 8.4 23.2 12:01.73
1 root 8 0 76 68 44 S 0.0 0.0 0:04.37 init
2 root 9 0 0 0 0 S 0.0 0.0 0:00.27 keventd
3 root 19 19 0 0 0 S 0.0 0.0 0:00.01
10 root -1 -20 0 0 0 S 0.0 0.0 0:00.00

EDIT: ACTUALLY THEY GET DISPLAY NEATLY NOT THE WAY THEY ARE DISPLAYED ABOVE...BUT WHEN I POST THE OUTPUT GETS SCRAMBLED

but if I take $reply and explode() it into an array and then use each element in the array as a row in the list....it works fine exept that the spacing and identing in each row gets lost:

2 root 9 0 0 0 0 S 0.0 0.0 0:00.27 keventd
3 root 19 19 0 0 0 S 0.0 0.0 0:00.01
10 root -1 -20 0 0 0 S 0.0 0.0 0:00.00

Beneath is the code for my second scenario (Iam a self taught newbie so be mercifull :P)

<?
$command = "sudo top -b -n 1";
$reply = shell_exec($command);
$processArray = explode("\n",$reply);
for($j = 0; $j < sizeof($processArray); $j++)
{
$current = "<pre>$processArray[$j]<pre>";
?>
<select size = "<?= sizeof($processArray) ?>">
<option value = <?= $j ?> > <?= $current?></option>
<?
}
?>
</select>

keefaz 12-12-2005 06:38 PM

Why not put the rows and values in a html table ?

ALInux 12-13-2005 07:04 AM

Because the idea is to allow the user to kill a process ...if I use a list the user can only choose one "existing" process...i.e. his choice is fool proof...


All times are GMT -5. The time now is 02:33 PM.