Re: Re: Extracting data from exec() call
| From: | Tamara Temple | Date: | Tue, 14 Jun 2011 22:15:33 +0000 |
| Subject: | Re: Re: Extracting data from exec() call | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-313533@lists.php.net to get a copy of this message | ||
On Jun 14, 2011, at 1:30 PM, Ashley M. Kirchner wrote:
On 6/14/2011 12:03 PM, Shawn McKenzie wrote:Seems what's best here is to do two explodes: $matches = preg_grep('/^\s*wmax/',$inputdata); if (count($matches) != 1) die("More or less than one wmax in data set"); $wmaxline = end($matches); list($var,$data) = explode(' = ',$wmaxline); $data = substr($data, 0, -2); $wmax = explode(', ',$data); print_r($wmax); which gives me the result of an array of data values. Array (--or to search for wmax = if($array = preg_grep('/^ wmax = $/', $output)) { $wmax = explode(', ', $array[0]); } array_shift($wmax); print_r($wmax); May need some more error checking.Yeah, error checking ... Can't search for '/^ wmax $/' because it just returns nothing. Dropping the '$' at the end works. The array_shift() also drops the first variable because the explode() call breaks it up as:wmax = 5, 5, 5.4 ... etc. First value = 'wmax = 5'And the explode also fails because data is not in $array[0], it's in $array[30]. Inserting an array_values() to reindex helps. So as of right now, I'm looking at:if ($array = preg_grep('/^ wmax = /', $output)) { $array = array_values($array); $wmax = explode(', ', $array[0]); } array_shift($wmax); print_r($wmax);The array_shift() call needs to shift out the 'wmax = ', but leave the first value. And, I still need to convert the whole thing into '$wmax = {5, 5, 5.4, ...}'. Right now it's an array of strings:Array ( [0] => wmax = 5 [1] => 5 [2] => 5 [3] => 5.4 )
[0] => 5
[1] => 5
[2] => 5
[3] => 5.4
[4] => 5.7
[5] => 5.1
[6] => 7.1
[7] => 6.1
[8] => 4.4
[9] => 9.5
------%<---------
[278] => 5.4
[279] => 6.1
[280] => 5.6
[281] => 5.9
[282] => 6.4
[283] => 9.5
[284] => 11.2
[285] => 15.8
[286] => 15
[287] => 13.6
)