Re: Extracting data from exec() call

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
        )


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux