fork download
  1. <?php
  2. $regexp = "/^\\s?(8|\\+\\s?7)((-|\\s|\\(|\\))*\\d(-|\\s|\\(|\\))*){10}$/";
  3. $allNumbers = [
  4. $correctNumbers = ['84951234567', '+74951234567', '8-495-1-234-567',
  5. ' 8 (8122) 56-56-56', '8-911-1234567', '8 (911) 12 345 67',
  6. '8-911 12 345 67', '8 (911) - 123 - 45 - 67', '+ 7 999 123 4567',
  7. '8 ( 999 ) 1234567', '8 999 123 4567']
  8. ];
  9. $matches = [];
  10. foreach ($allNumbers as $numbers) {
  11. foreach ($numbers as $number) {
  12. $correctText = str_replace(" ", "", $number);
  13. $correctText = str_replace("-", "", $correctText);
  14. $correctText = str_replace("(", "", $correctText);
  15. $correctText = str_replace(")", "", $correctText);
  16. $memeRegexp = "(\\+7)";
  17. $correctText = preg_replace($memeRegexp,"8", $correctText);
  18. if (preg_match($regexp, $correctText, $matches)) {
  19. echo "Правильный номер: {$matches[0]}<br/>";
  20. } else {
  21. echo "Ошибка! Введите номер формата: +7/8xxxxxxxxxx<br/>";
  22. }
  23. }
  24. }
  25.  
  26.  
  27. ?>
Runtime error #stdin #stdout #stderr 0.02s 23704KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Fatal error:  Uncaught Error: Call to undefined function mb_internal_encoding() in /home/CTR0Pt/prog.php:2
Stack trace:
#0 {main}
  thrown in /home/CTR0Pt/prog.php on line 2