views:

34

answers:

2

I'm looking to convert US Format Zip Code 00000-1234 to 00000. But the zip may also be Canadian, UK or the World for that matter.

So I guess a sanity check would be that you have 5 digits all 0-9 followed by a dash followed by 4 digits 0-9. If that fails leave the string alone if it passes trim off everything to the Right of the 5th digit.

Greg :-)

+1  A: 

Try

preg_replace('/(\d{5})\-\d{4}/', '$1', $zipcode);
S.Mark
+1  A: 
$output = preg_replace('!\(d{5})-\d{4}!', '$1', $input);
cletus