Re[2]: Breaking up data efficiently

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

 



Hi,

Tuesday, June 28, 2005, 10:26:12 AM, you wrote:

TR> This ay work:
TR> <?
TR> $str = 'Melbourne, AU, 21-07-2005 14:00:00|Perth, AU,
TR> 21-07-2005 18:00:00|Perth, AU, 25-07-2005 14:00:00|Melbourne, AU,
TR> 25-07-2005 18:00:00';
TR> preg_match_all('/(\w+),\s*(\w+),\s*([0-9-]+)\s([0-9:]+)(?=\|)/s',$str,$match);
TR> print_r($match);

A different way that will generate what you actually need :)

function build($data){
  global $path;
  $i = count($path);
  $path[$i]['location'] = $data[1];
  $path[$i]['country'] = $data[2];
  $path[$i]['datetime'] = $data[3];
}
$path = array();
$str = 'Melbourne, AU, 21-07-2005 14:00:00|Perth, AU, 21-07-2005 18:00:00|Perth, AU, 25-07-2005 14:00:00|Melbourne, AU, 25-07-2005 18:00:00';
preg_replace_callback('/(\w+),\s*(\w+),\s([0-9-]+\s[0-9:]+)(?=\|)/s','build',$str);
print_r($path);




-- 
regards,
Tom

-- 
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