Looking at a mailbox check, you need to know if such a check exists. I have the "Address" field, divided into address 1 and address 2 (where such information about PO, Apt, Suite will be displayed)
Example:
Address 1: 123 Main Street Address 2: Suite 100 City: Any Town State: Any State Zip: Any Zip
Mailbox (can also be used for BIN for BOX) Examples:
- Mailbox 123
- PO Box 123
- PO 123
- Mailbox 123
- PO 123
- Box 123
123
- 123
- POB 123
- POB 123
- POB 123
- Message 123
- Mailbox 123
(I know that I probably need to check more, but this is what I could think of, feel free to add or fix)
I know RegEx is best suited for this, and I saw other questions in Stack # 1 , # 2
Using RegEx from another question, I get good results, but it misses some, I think it should catch
$arr = array ( 'PO Box 123', 'PO Box 123', 'PO 123', 'Post Office Box 123', 'PO 123', 'Box 123', '#123', // no match '123', // no match 'POB 123', 'POB 123', // no match 'POB 123', // no match 'Post 123', // no match 'Post Box 123' // no match ); foreach($arr as $po) { if(preg_match("/^\s*((P(OST)?.?\s*O(FF(ICE)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", $po)) { echo "A match was found: $po\n"; } else { echo "A match was not found: |$po| \n"; } }
Why doesn't it catch the last two values ββin the array?
php regex
Phill pafford
source share