Re: Extracting data from exec() call

From: Date: Tue, 14 Jun 2011 18:30:39 +0000
Subject: Re: Extracting data from exec() call
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-313525@lists.php.net to get a copy of this message
On 6/14/2011 12:03 PM, Shawn McKenzie wrote:
--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
        )


« previous php.general (#313525) next »