fork(7) download
  1. <?php
  2. $words = array_flip(array(0=>'zero',1=>'one',2=>'two',3=>'three',4=>'four',5=>'five',6=>'six',7=>'seven',8=>'eight',9=>'nine'));
  3. $s = "my long STRING with 124 mynumberis 8989243three56 some Numbers 402three1345233 5023one345233";
  4. $test= array();
  5. foreach (explode(" ", $s) as $tocken) {
  6. $num = strtr(strtolower($tocken), $words);
  7. if(is_numeric($num))
  8. array_push($test,$tocken);
  9. }
  10.  
  11. $b = array();
  12. $pattern = '/^(?:\((\+?\d+)?\)|(\+\d{0,3}))? ?\d{2,3}([-\.]?\d{2,3} ?){3,4}/';
  13. foreach ($test as $value) {
  14. $value = strtolower($value);
  15. // Capture also the numbers so we just concat later, no more string substitution.
  16. $matches = preg_split('/(\d+)/', $value, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
  17.  
  18. if ($matches) {
  19. $newValue = array();
  20. foreach ($matches as $word) {
  21. // Replace if a valid word number.
  22. $newValue[] = (isset($words[$word]) ? $words[$word] : $word);
  23. }
  24. $newValue = implode($newValue);
  25. if (preg_match($pattern, $newValue)) {
  26. $b[] = $value;
  27. var_dump($b);
  28. }
  29. }
  30. }
  31.  
  32. //echo implode("\n", $b);
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
array(1) {
  [0]=>
  string(14) "8989243three56"
}
array(2) {
  [0]=>
  string(14) "8989243three56"
  [1]=>
  string(15) "402three1345233"
}
array(3) {
  [0]=>
  string(14) "8989243three56"
  [1]=>
  string(15) "402three1345233"
  [2]=>
  string(13) "5023one345233"
}