I have content like
San Clemente, CA 92673
or
Arlington, TX 76012-3693
And I need to split it into CityAndState
and Zip
.
Some
I'm trying:
$moreAddressInfo = preg_split('^[0-9.]{5,}^', $row2['cityAndZip'],null,PREG_SPLIT_DELIM_CAPTURE);
(also tried without the flag)
... the CityState portion is getting returned just fine, but the main Zip info is missing
(for the above two examples, $moreAddressInfo[1] would equal '' and '-3693', respectively).
Any pointers ?
Try this:
$moreAddressInfo = preg_split('~\s+(?=[0-9]{5})~', $row2['cityAndZip']);
\s+
matches one or more whitespace characters.
(?=[0-9]{5})
is a positive lookahead; it asserts that the next part of the string is five digits, but doesn't consume them.
So your delimiter is some whitespace that's followed by five digits.