<?php
function checkText($text, $patternRus, $patternEng){
foreach ($array as $word) {
echo "{$highlights} ";
}
echo "{$highlights} ";
}
}
echo "\n";
}
function correctText($text, $replacementRus, $replacementEng){
$correctedArr = [];
foreach ($array as $word){
if (preg_match('/^([а-яё.,;?!]+)([a-z]+)/ui', $word)){ //пришлось добавить условие начала строки, чтобы точно знать, на каком языке слово $word = strtr($word, $replacementRus); }
if (preg_match('/^([a-z.,;?!]+)([а-яё]+)/ui', $word)){ $word = strtr($word, $replacementEng); }
}
$correctedStr = implode(' ', $correctedArr); return $correctedStr;
}
$replacementRus = ['a' => 'а',
'A' => 'А',
'B' => 'В',
'C' => 'С',
'c' => 'с',
'e' => 'е',
'E' => 'Е',
'H' => 'Н',
'K' => 'К',
'M' => 'М',
'o' => 'о',
'O' => 'О',
'p' => 'р',
'P' => 'Р',
'T' => 'Т',
'x' => 'х',
'X' => 'Х',
'y' => 'у'];
$text = "выпoлнение рабoт по комплекснoму благоустрoйству двoрoвой территoрии по адресу: ул.Kурьянoва д.2 к.2 tеrritоry батapeя st.Аnger, ПPИBET";
$patternRus = '/([а-яё.,;?!]+)([a-z]+)/ui';
$patternEng = '/([a-z.,;?!]+)([а-яё]+)/ui';
echo "Исходный текст:\n";
checkText($text, $patternRus, $patternEng);
$correctedText = correctText($text, $replacementRus, $replacementEng);
echo "Исправленный текст:\n";
checkText($correctedText, $patternRus, $patternEng);
?>
PD9waHAKICAgIGVycm9yX3JlcG9ydGluZygtMSk7CiAgICBtYl9pbnRlcm5hbF9lbmNvZGluZygndXRmLTgnKTsKCiAgICBmdW5jdGlvbiBjaGVja1RleHQoJHRleHQsICRwYXR0ZXJuUnVzLCAkcGF0dGVybkVuZyl7CiAgICAgICAgJGFycmF5ID0gZXhwbG9kZSAoIiAiLCAkdGV4dCk7CgkgICAgZm9yZWFjaCAoJGFycmF5IGFzICR3b3JkKQkgICAgewoJCSAgICBpZiAocHJlZ19tYXRjaCgnL15b0LAt0Y/RkV0vdWknLCAkd29yZCkp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kJCWFycmF5X3B1c2goJGNvcnJlY3RlZEFyciwgJHdvcmQpOwogICAgICAgIH0KCQkkY29ycmVjdGVkU3RyID0gaW1wbG9kZSgnICcsICRjb3JyZWN0ZWRBcnIpOwoJCXJldHVybiAkY29ycmVjdGVkU3RyOwoJfQoJCiAgICAkcmVwbGFjZW1lbnRSdXMgPSBbJ2EnID0+ICfQsCcsCiAgICAgICAgICAgICAgICAgICAgICAgJ0EnID0+ICfQkCcsCiAgICAgICAgICAgICAgICAgICAgICAgJ0InID0+ICfQkicsCiAgICAgICAgICAgICAgICAgICAgICAgJ0MnID0+ICfQoScsIAogICAgICAgICAgICAgICAgICAgICAgICdjJyA9PiAn0YEnLCAKICAgICAgICAgICAgICAgICAgICAgICAnZScgPT4gJ9C1JywgCiAgICAgICAgICAgICAgICAgICAgICAgJ0UnID0+ICfQlScsIAogICAgICAgICAgICAgICAgICAgICAgICdIJyA9PiAn0J0nLAogICAgICAgICAgICAgICAgICAgICAgICdLJyA9PiAn0JonLAogICAgICAgICAgICAgICAgICAgICAgICdNJyA9PiAn0JwnLAogICAgICAgICAgICAgICAgICAgICAgICdvJyA9PiAn0L4nLAogICAgICAgICAgICAgICAgICAgICAgICdPJyA9PiAn0J4nLAogICAgICAgICAgICAgICAgICAgICAgICdwJyA9PiAn0YAnLAogICAgICAgICAgICAgICAgICAgICAgICdQJyA9PiAn0KAnLAogICAgICAgICAgICAgICAgICAgICAgICdUJyA9PiAn0KInLAogICAgICAgICAgICAgICAgICAgICAgICd4JyA9PiAn0YUnLAogICAgICAgICAgICAgICAgICAgICAgICdYJyA9PiAn0KUnLAogICAgICAgICAgICAgICAgICAgICAgICd5JyA9PiAn0YMnXTsKCSRyZXBsYWNlbWVudEVuZyA9IGFycmF5X2ZsaXAoJHJlcGxhY2VtZW50UnVzKTsKCQogICAgJHRleHQgPSAi0LLRi9C/b9C70L3QtdC90LjQtSDRgNCw0LFv0YIg0L/QviDQutC+0LzQv9C70LXQutGB0L1v0LzRgyDQs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