<?php
function checkText( $text , $patternRus , $patternEng ) {
return "В тексте есть заменённые буквы.\n " ;
} else {
return "В тексте нет заменённых букв.\n " ;
}
}
function showHighlightedText( $text , $patternRus , $patternEng ) {
foreach ( $array as $word ) {
echo "{$highlights} " ;
}
echo "{$highlights} " ;
}
}
echo "\n " ;
}
function correctText( $text ) {
$replacementRus = [
'a' => 'а' ,
'A' => 'А' ,
'B' => 'В' ,
'C' => 'С' ,
'c' => 'с' ,
'e' => 'е' ,
'E' => 'Е' ,
'H' => 'Н' ,
'K' => 'К' ,
'M' => 'М' ,
'o' => 'о' ,
'O' => 'О' ,
'p' => 'р' ,
'P' => 'Р' ,
'T' => 'Т' ,
'x' => 'х' ,
'X' => 'Х' ,
'y' => 'у' ] ;
$correctedArr = [ ] ;
foreach ( $array as $word ) {
if ( preg_match ( '/^[а-яё]/ui' , $word ) ) { //упростил проверку языка $word = strtr ( $word , $replacementRus ) ; }
$word = strtr ( $word , $replacementEng ) ; }
}
$correctedStr = implode ( ' ' , $correctedArr ) ; return $correctedStr ;
}
$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 " ;
echo checkText( $text , $patternRus , $patternEng ) ;
showHighlightedText( $text , $patternRus , $patternEng ) ;
$correctedText = correctText( $text ) ;
echo "##Исправленный текст##<\n " ;
echo checkText( $correctedText , $patternRus , $patternEng ) ;
showHighlightedText( $correctedText , $patternRus , $patternEng ) ;
?>
PD9waHAKICAgIGVycm9yX3JlcG9ydGluZygtMSk7CiAgICBtYl9pbnRlcm5hbF9lbmNvZGluZygndXRmLTgnKTsKCglmdW5jdGlvbiBjaGVja1RleHQoJHRleHQsICRwYXR0ZXJuUnVzLCAkcGF0dGVybkVuZyl7CgkJaWYg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gICAgICAnQicgPT4gJ9CSJywKICAgICAgICAgICAgICAgICAgICAnQycgPT4gJ9ChJywgCiAgICAgICAgICAgICAgICAgICAgJ2MnID0+ICfRgScsIAogICAgICAgICAgICAgICAgICAgICdlJyA9PiAn0LUnLCAKICAgICAgICAgICAgICAgICAgICAnRScgPT4gJ9CVJywgCiAgICAgICAgICAgICAgICAgICAgJ0gnID0+ICfQnScsCiAgICAgICAgICAgICAgICAgICAgJ0snID0+ICfQmicsCiAgICAgICAgICAgICAgICAgICAgJ00nID0+ICfQnCcsCiAgICAgICAgICAgICAgICAgICAgJ28nID0+ICfQvicsCiAgICAgICAgICAgICAgICAgICAgJ08nID0+ICfQnicsCiAgICAgICAgICAgICAgICAgICAgJ3AnID0+ICfRgCcsCiAgICAgICAgICAgICAgICAgICAgJ1AnID0+ICfQoCcsCiAgICAgICAgICAgICAgICAgICAgJ1QnID0+ICfQoicsCiAgICAgICAgICAgICAgICAgICAgJ3gnID0+ICfRhScsCiAgICAgICAgICAgICAgICAgICAgJ1gnID0+ICfQpScsCiAgICAgICAgICAgICAgICAgICAgJ3knID0+ICfRgyddOwoJCSRyZXBsYWNlbWVudEVuZyA9IGFycmF5X2ZsaXAoJHJlcGxhY2VtZW50UnVzKTsKCQkkYXJyYXkgPSBleHBsb2RlICgiICIsICR0ZXh0KTsKCQkkY29ycmVjdGVkQXJyID0gW107CgkgICAgZm9yZWFjaCAoJGFycmF5IGFzICR3b3JkKXsKCQkJaWYgKHByZWdfbWF0Y2goJy9eW9CwLdGP0ZFdL3VpJywgJHdvcmQpKXsgLy/Rg9C/0YDQvtGB0YLQuNC7INC/0YDQvtCy0LXRgNC60YMg0Y/Qt9GL0LrQsAoJCQkgICAgJHdvcmQgPSBzdHJ0cigkd29yZCwgJHJlcGxhY2VtZW50UnVzKTsKCQkgICAgfQoJCSAgICBpZiAocHJlZ19tYXRjaCgnL15bYS16XS91aScsICR3b3JkKSl7CgkJCSAgICAkd29yZCA9IHN0cnRyKCR3b3JkL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