<?php
// your code goes here
$addr1 = "5285 KEYES DR KALAMAZOO MI 49004 2613";
$addr2 = "PO BOX 35 COLFAX LA 71417 35";
$addr3 = "64938 MAGNOLIA LN APT B PINEVILLE LA 71360-9781";
function extract_zipcode($address, $remove_statecode = false) {
$zipcode = preg_match("/\b[A-Z]{2}\s+\d{5}(-\d{4})?\b/", $address, $matches); return $remove_statecode ?
preg_replace("/[^\d\-]/", "", extract_zipcode
($matches[0])) : $matches[0]; }
echo extract_zipcode($addr1, 1) . ' ';
echo extract_zipcode($addr2) . ' ';
PD9waHAKCi8vIHlvdXIgY29kZSBnb2VzIGhlcmUKCgoKJGFkZHIxID0gIjUyODUgS0VZRVMgRFIgIEtBTEFNQVpPTyBNSSA0OTAwNCAyNjEzIjsKJGFkZHIyID0gIlBPIEJPWCAzNSAgQ09MRkFYIExBIDcxNDE3IDM1IjsKJGFkZHIzID0gIjY0OTM4IE1BR05PTElBIExOIEFQVCBCIFBJTkVWSUxMRSBMQSA3MTM2MC05NzgxIjsKCmZ1bmN0aW9uIGV4dHJhY3RfemlwY29kZSgkYWRkcmVzcywgJHJlbW92ZV9zdGF0ZWNvZGUgPSBmYWxzZSkgewogICAgJHppcGNvZGUgPSBwcmVnX21hdGNoKCIvXGJbQS1aXXsyfVxzK1xkezV9KC1cZHs0fSk/XGIvIiwgJGFkZHJlc3MsICRtYXRjaGVzKTsKICAgIHJldHVybiAkcmVtb3ZlX3N0YXRlY29kZSA/IHByZWdfcmVwbGFjZSgiL1teXGRcLV0vIiwgIiIsIGV4dHJhY3RfemlwY29kZSgkbWF0Y2hlc1swXSkpIDogJG1hdGNoZXNbMF07Cn0KCiAgICBlY2hvIGV4dHJhY3RfemlwY29kZSgkYWRkcjEsIDEpIC4gJyAnOwogICAgZWNobyBleHRyYWN0X3ppcGNvZGUoJGFkZHIyKSAuICcgJzsK