fork download
  1. <?php
  2.  
  3. $pns = <<< LOL
  4. 941-751-6550 ext 2204
  5. (941) 751-6550 ext 2204
  6. (941)751-6550 ext 2204
  7. 9417516550 ext 2204
  8. 941-751-6550 e 2204
  9. 941-751-6550 ext 2204
  10. 941-751-6550 extension 2204
  11. 941-751-6550 x2204
  12. (941) 751-6550
  13. (941)7516550
  14. 941-751-6550
  15. 941-751-6550
  16. LOL;
  17.  
  18. preg_match_all('/^([(\d )\-]+)\s?(?:e.*?|x.*?)?(\d+)?$/sim', $pns, $matches, PREG_PATTERN_ORDER);
  19. for ($i = 0; $i < count($matches[1]); $i++) {
  20. $phone = preg_replace('#[\-\(\)\s]#','', $matches[1][$i]);
  21. $extension = preg_replace('#[^0-9]#','', $matches[2][$i]);
  22. if ($phone == '9417516550' && $extension == '2204') {
  23. echo "PASS: phone: $phone ext: $extension\n";
  24. } else {
  25. echo "FAIL: phone: $phone ext: 0\n";
  26. }
  27. }
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
PASS: phone: 9417516550 ext: 2204
PASS: phone: 9417516550 ext: 2204
PASS: phone: 9417516550 ext: 2204
PASS: phone: 9417516550 ext: 2204
PASS: phone: 9417516550 ext: 2204
PASS: phone: 9417516550 ext: 2204
PASS: phone: 9417516550 ext: 2204
PASS: phone: 9417516550 ext: 2204
FAIL: phone: 9417516550 ext: 0
FAIL: phone: 9417516550 ext: 0
FAIL: phone: 9417516550 ext: 0
FAIL: phone: 9417516550 ext: 0