fork download
  1. <?php
  2.  
  3.  
  4.  
  5. //class Phone extends Filter{
  6.  
  7. $text = "my long STRING with 124 mynumberis 8989243three56 some 40one34two3473 Numbers 402three1345233 5023one345233";
  8.  
  9. $text = $_GET['text'];
  10.  
  11. $words = array('nice', 'good');
  12.  
  13. parse($text, $words);
  14.  
  15. function parse($text, $words)
  16.  
  17. {
  18.  
  19. $arrwords = array_flip(array(0=>'zero',1=>'one',2=>'two',3=>'three',4=>'four',5=>'five',6=>'six',7=>'seven',8=>'eight',9=>'nine'));
  20.  
  21.  
  22.  
  23. $test= array();
  24.  
  25. foreach (explode(" ", $text) as $tocken)
  26.  
  27. {
  28.  
  29. $num = strtr(strtolower($tocken), $arrwords);
  30.  
  31. if(is_numeric($num))
  32.  
  33. array_push($test,$tocken);
  34.  
  35. }
  36.  
  37. //print_r($test);
  38.  
  39. $b = array();
  40.  
  41. $pattern = '/^(?:\((\+?\d+)?\)|(\+\d{0,3}))? ?\d{2,3}([-\.]?\d{2,3} ?){3,4}/';
  42.  
  43. foreach ($test as $value)
  44.  
  45. {
  46.  
  47. $value = strtolower($value);
  48.  
  49. // Capture also the numbers so we just concat later, no more string substitution.
  50.  
  51. $matches = preg_split('/(\d+)/', $value, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
  52.  
  53.  
  54.  
  55. if ($matches)
  56.  
  57. {
  58.  
  59. $newValue = array();
  60.  
  61. foreach ($matches as $word)
  62.  
  63. {
  64.  
  65. // Replace if a valid word number.
  66.  
  67. $newValue[] = (isset($arrwords[$word]) ? $arrwords[$word] : $word);
  68.  
  69. }
  70.  
  71. $newValue = implode($newValue);
  72.  
  73. if (preg_match($pattern, $newValue))
  74.  
  75. {
  76.  
  77. $b[] = $value;
  78.  
  79. }
  80.  
  81. }
  82.  
  83. }
  84.  
  85. print_r($b);
  86.  
  87. }
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95. ?>
  96.  
  97.  
  98.  
  99.  
Success #stdin #stdout #stderr 0.01s 20520KB
stdin
Standard input is empty
stdout
Array
(
)



stderr
PHP Notice:  Undefined index: text in /home/b5J3ZO/prog.php on line 9