Having fits with input to array
| From: | Susan Ator | Date: | Fri, 14 Nov 2003 17:00:18 +0000 |
| Subject: | Having fits with input to array | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-169655@lists.php.net to get a copy of this message | ||
I am sending this again as it seems like it didn't go the first time.
I have a series of commands like so (with different programs on each line):
display_pgm("bash");
Here is the bare bones of the function 'display_pgm':
function display_pgm ($pgm) {
$cmd = " -C $pgm --no-headers -o
pid,fname,state,vsz,start_time,flag,user,cputime,args --cols 200";
$ps =
ps $cmd;
$ps2 = ereg_replace("\n", ",", $ps);
eval("\$psArray = array(\$ps2);");
print_r($psArray);
}
If I can't get this part to work the rest of the function is a no-go. When I
do this I get only one element in my array instead of the 3-4 I should be
getting. I'm using bash for testing since I know that will always give a
return.
I've also tried:
eval("\$psArray = array(\"$ps2\");");
and
eval("\$psArray = array($ps2);"); - This one gives me a parse error
(Parse error: parse error, unexpected T_STRING, expecting ')' in
/var/www/html/ps.php(25) : eval()'d code on line 1)
When I have used the same eval in another page I get each part separated by
the comma as a separate element in the array. What in the world am I doing
wrong?
susan