fork(1) download
  1. <?php
  2.  
  3. $regexp = '/(\\b([a-zA-Z]+)([а-яёА-ЯЁ]+)\\b)|(\\b([а-яёА-ЯЁ]+)([a-zA-Z]+)([а-яёА-ЯЁ]+)\\b)|(\\b([а-яёА-ЯЁ]+)([a-zA-Z]+)\\b)|(\\b([a-zA-Z]+)([а-яёА-ЯЁ]+)([a-zA-Z]+)\\b)/u';
  4. $regexpLetter = ['/a/', '/A/', '/c/', '/C/', '/e/', '/E/', '/K/', '/O/', '/o/', '/y/'];
  5. $replaceLetter = ['а', 'А', 'с', 'С', 'е', 'Е', 'К', 'О', 'о', 'у'];
  6.  
  7. $text = 'Kartоn это картoнка';
  8. $words = explode(" ", $text);
  9.  
  10. $matches = array();
  11. preg_match_all($regexp, $text, $matches);
  12.  
  13. $correctWOrds = array();
  14.  
  15. for($i = 0; $i < count($matches[0]); $i++) {
  16. $correctWOrds[$i] = preg_replace($regexpLetter, $replaceLetter, $matches[0][$i]);
  17. }
  18.  
  19. for($i = 0; $i < count($words); $i++) {
  20. for($b = 0; $b < count($correctWOrds); $b++) {
  21. if ($words[$i] == $matches[0][$b]) $words[$i] = $correctWOrds[$b];
  22. }
  23. }
  24.  
  25. $correctText = implode(' ', $words);
  26.  
  27. echo $correctText;
Success #stdin #stdout 0.03s 24928KB
stdin
Standard input is empty
stdout
Каrtоn это картонка