RE: [PHP] Having fits with input to array

From: Date: Fri, 14 Nov 2003 18:32:28 +0000
Subject: RE: [PHP] Having fits with input to array
Groups: php.general 
Request: Send a blank email to php-general+get-169665@lists.php.net to get a copy of this message
Well, my understanding is the array($ps2); bit takes care of that. What I need to do is call the ps command with the options listed for each program I'm interested in tracking, take each line output and treat it as an element in an array. Then, for each array element I need to create another array with each element in the line output as an array element. For example, the command: ps -C bash --no-headers -o fname,state,vsz,start_time,flag,user,cputime,args --cols 200 gives me the output of: bash S 4396 Nov13 000 sator 00:00:00 -bash bash S 4392 Nov13 000 sator 00:00:00 -bash bash S 4396 Nov13 000 sator 00:00:00 -bash The array I end up with using this code (where $pgm is bash): $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); is: Array ( [0] => bash sleeping 4396 Nov13 000 sator 00:00:00 -bash,bash sleeping 4392 Nov13 000 sator 00:00:00 -bash,bash sleeping 4396 Nov13 000 sator 00:00:00 -bash ) where I need it to be: Array ( [0] => bash S 4396 Nov13 000 sator 00:00:00 -bash [1] => bash S 4392 Nov13 000 sator 00:00:00 -bash [2] => bash S 4396 Nov13 000 sator 00:00:00 -bash ) and the second array needs to be: Array ( [0] => Array ( [0] => bash [1] => S [2] => 4396 [3] => Nov13 [4] => 000 [5] => sator [6] => 00:00:00 [7] => -bash ) etc... ) THIS is what I am unable to do. Does anyone have any ideas? susan -----Original Message----- From: Lowell Allen [mailto:la@lowellallen.com] Sent: Friday, November 14, 2003 12:16 PM To: PHP Subject: Re: [PHP] Having fits with input to array For $psArray to be an array, shouldn't it be: eval("\$psArray[] = array(\$ps2);"); -- Lowell Allen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#169665) next »