fork(2) download
  1. <?php
  2.  
  3.  
  4. $regexp = "/(([а-я]+[a-z]+)|([a-z]+[а-я]+))\\w*/ui";
  5. $wordRegexp = "/[a-z]/ui";
  6.  
  7. $string = "Пocтaвкa мяco гoвядины,бecкостнoe для нужд государственного бюджетного учреждения здравоохранения Республики Башкортостан Инфекционная клиническая больница № 4 города Уфа \n";
  8.  
  9. $matches = [];
  10. $subjects = [];
  11. $wordTemplate = array(
  12. 'a' => 'а',
  13. 'c' => 'с',
  14. 'o' => 'о',
  15. 'e' => 'е',
  16. 'y' => 'у',
  17. 'x' => 'х',
  18. 'p' => 'р',
  19. );
  20.  
  21. preg_match_all($regexp, $string, $matches);
  22. $matches = $matches[0];
  23.  
  24. for ($i=(count($matches)-1); $i>=0; $i--) {
  25.  
  26. $problemWord = $matches[$i];
  27.  
  28. preg_match_all($wordRegexp, $problemWord, $subjects);
  29. $subjects = $subjects[0];
  30.  
  31. for ($j=(count($subjects)-1); $j>=0; $j--) {
  32.  
  33. $problemLetter = $subjects[$j];
  34.  
  35. foreach ($wordTemplate as $key => $value) {
  36.  
  37. if ($key == $problemLetter) {
  38. $letterRegexp = "/$key/ui";
  39. $problemWord = preg_replace($letterRegexp, "[{$value}]", $problemWord);
  40. }
  41.  
  42. }
  43.  
  44. }
  45. echo "problemWord after foreach: $problemWord \n";
  46. }
  47. ?>
Success #stdin #stdout 0.01s 82624KB
stdin
Standard input is empty
stdout
problemWord after foreach: б[е][с]костн[о][е] 
problemWord after foreach: г[о]вядины 
problemWord after foreach: мя[с][о] 
problemWord after foreach: П[о][с]т[а]вк[а]