<?php

error_reporting(-1);

$regexp = "/(([а-я]+[a-z]+)|([a-z]+[а-я]+))\\w*/ui";
$wordRegexp = "/[a-z]/ui";

$string = "Пocтaвкa мяco гoвядины,бecкостнoe для нужд государственного бюджетного учреждения здравоохранения Республики Башкортостан Инфекционная клиническая больница № 4 города Уфа  \n";

$matches = [];
$subjects = [];
$wordTemplate = array(
  'a' => 'а', 
  'c' => 'с',
  'o' => 'о',
  'e' => 'е',
  'y' => 'у',
  'x' => 'х',
  'p' => 'р',
);

preg_match_all($regexp, $string, $matches);
$matches = $matches[0];

for ($i=(count($matches)-1); $i>=0; $i--) {
	
  $problemWord = $matches[$i];
  
  preg_match_all($wordRegexp, $problemWord, $subjects);
  $subjects = $subjects[0];
  
  for ($j=(count($subjects)-1); $j>=0; $j--) {
  	
    $problemLetter = $subjects[$j];
	
    foreach ($wordTemplate as $key => $value) {
    	
      if ($key == $problemLetter) {
        $letterRegexp = "/$key/ui";
        $problemWord = preg_replace($letterRegexp, "[{$value}]", $problemWord);
      }
      
    }
    
  }
  echo "problemWord after foreach: $problemWord \n";
} 
?>