Re: Simple RegEx question

From: Date: Tue, 25 Dec 2007 04:02:15 +0000
Subject: Re: Simple RegEx question
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-266267@lists.php.net to get a copy of this message
On Dec 24, 2007, at 7:59 PM, Casey <heavyccasey@gmail.com> wrote:
On Dec 24, 2007, at 7:34 PM, M5 <m5@renefournier.com> wrote:
I'm learning regular expressions, and trying to figure out what's possible and what's not. Any ideas of how to create a preg_match expression to parse following three lines: Calgary, AB T2A6C1
Toronto, ON     T4M 0B0
Saint John,  NB    E2L 4L1
...such that it splits each line into City, Province and Postalcode (irrespective of occasional white space), e.g.: Array (
  [city]    => "Calgary",
  [prov]    => "AB",
  [postal]    => "T2A 6C1"
) Array (
  [city]    => "Toronto",
  [prov]    => "ON",
[postal]=> "T4M 0B0" ) Array (
  [city]    => "Saint John",
  [prov]    => "NB",
[postal]=> "E2L 4L1" ) --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Try this: $places = array(); $lines = explode("\n", $toparse); foreach ($lines as $i => $line) list($places[$i]['city'], $places[$i]['prov'], $places[$i]['postal']) = explode(' ', $line, 3);' I'm very sorry about that, Ive been wrong all week!
It doesn't parse Saint John correctly :(

« previous php.general (#266267) next »