Re: Breaking up data efficiently

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

 



Hi,

Tuesday, June 28, 2005, 9:34:28 AM, you wrote:
WK> Hi All,

WK> I'm working on an aircraft booking system and it has multiple
WK> origin/destination data, concatenated into a single line:


WK> /***** BEGIN DATA *****/

WK> Melbourne, AU, 21-07-2005 14:00:00|Perth, AU, 21-07-2005 18:00:00|Perth,
WK> AU, 25-07-2005 14:00:00|Melbourne, AU, 25-07-2005 18:00:00

WK> /***** END DATA *****/


WK> As you can see, each origin/destination is separated by a pipe '|', and
WK> then, each origin/destination data has its location, country and
WK> datetime of departure/arrival, separated by comma ','.

WK> I'm splitting them up into array of location, country and datetime using
WK> the following:


WK> /***** BEGIN CODE *****/

WK> $itenary = explode('|', $booking->booking_flight_details);
			
WK> $size = count($itenary);

WK> for($i=0; $i < $size; $i++) {
WK>     list($path[$i]['location'],
WK>          $path[$i]['country'],
WK>          $path[$i]['datetime']) = explode(',', $itenary[$i]);
WK> }

WK> /***** END CODE *****/



WK> *Question*: Is the above the code an effective way to do it? Or is there
WK> a better/faster way?

WK> Somehow, it feels like there's lots of things going through the above code.

WK> Please advise. Thanks.

This ay work:
<?
$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_match_all('/(\w+),\s*(\w+),\s*([0-9-]+)\s([0-9:]+)(?=\|)/s',$str,$match);
print_r($match);

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