Advertisement
Filkolev

Phone Numbers

Jan 12th, 2015
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.82 KB | None | 0 0
  1. <?php
  2.  
  3. $string = $_GET["numbersString"];
  4. preg_match_all("/([A-Z][A-Za-z]*)(?:[^+a-zA-Z]*?)(\+?(?=\d)[\d()\/.\- ]{2,})/", $string, $pairs, PREG_SET_ORDER);
  5.  
  6. $output = array();
  7. foreach ($pairs as $pair) {
  8.     $name = trim($pair[1]);
  9.     if(strlen($name) == 0){
  10.         continue;
  11.     }
  12.     $number = trim($pair[2]);
  13.     if (preg_match("/\d{2,}/", $number, $outputNumber) == 0) {
  14.         continue;
  15.     }else{
  16.         $number = preg_replace("/[()\/\.\-\s]/", "", $number);
  17.     }
  18.     $newPair = array("name" => $name, "number" => $number);
  19.     array_push($output, $newPair);
  20. }
  21.  
  22. if (count($output) == 0) {
  23.     echo "<p>No matches!</p>";
  24. }
  25. echo "<ol>";
  26. foreach ($output as $pair) {
  27.     echo "<li><b>"
  28.     . htmlentities($pair["name"])
  29.     . ":</b> "
  30.     . htmlentities($pair["number"])
  31.     . "</li>";
  32. }
  33. echo "</ol>";
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement