Re[2]: [PHP] Breaking up data efficiently
| From: | Tom Rogers | Date: | Tue, 28 Jun 2005 00:47:02 +0000 |
| Subject: | Re[2]: [PHP] Breaking up data efficiently | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-217723@lists.php.net to get a copy of this message | ||
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