<?php
//"Grammar Nazi" с функцией-обёрткой
function fixGrammar( $regexp , $callback , $text ) {
return $text ;
}
function copyCase( $neededLetter , $symbol ) {
}
return $neededLetter ;
}
$text = "ЗДЕЛАЛ СДЕСЬ КООРДИНАЛЬНО Привет,Жырный!труд:Шырокий?пассаЖЫР;зделаю Координально но, например СДЕСЬ сдесь решена проблема ушыбов.
ЗДЕЛАНО многое а? ведь эти ушы зделали мы. Один ананас но зато как ЗДЕЛАННЫЙ" ;
$simpleReplace = [ '/(к)оординально/ui' => '$1ардинально' , //кардинально
'/([,;!?:])([^,;!?:\\s]+)/u' => '$1 $2' , //пробелы после знаков препинания
'/([а-яё]+)\\s+((?:а|но)\\b)/ui' => '$1, $2' ] ; //знаки препинания
foreach ( $simpleReplace as $pattern => $replacement ) {
}
$text = fixGrammar( '/(с)(десь)/ui' ,
function ( $matches ) {
$letter = copyCase( 'з' , $matches [ 1 ] ) ;
$word = "{$letter} {$matches[2]} " ;
return $word ;
} , $text ) ;
$text = fixGrammar( '/(з)(дела)((?:ю|л|н)\\s*)/ui' ,
function ( $matches ) {
$letter = copyCase( 'с' , $matches [ 1 ] ) ;
$word = "{$letter} {$matches[2]} {$matches[3]} " ;
return $word ;
} , $text ) ;
$text = fixGrammar( '/([а-яё]*(?:ж|ш))(ы)([а-яё]*)/ui' ,
function ( $matches ) {
$letter = copyCase( 'и' , $matches [ 2 ] ) ;
$word = "{$matches[1]} {$letter} {$matches[3]} " ;
return $word ;
} , $text ) ;
echo $text ;
?>
PD9waHAKLy8iR3JhbW1hciBOYXppIiDRgSDRhNGD0L3QutGG0LjQtdC5LdC+0LHRkdGA0YLQutC+0LkKICAgIGVycm9yX3JlcG9ydGluZygtMSk7CiAgICBtYl9pbnRlcm5hbF9lbmNvZGluZygndXRmLTgnKTsKCiAgICBmdW5jdGlvbiBmaXhHcmFtbWFyKCRyZWdleHAsICRjYWxsYmFjaywgJHRleHQpewogICAgICAgICR0ZXh0ID0gcHJlZ19yZXBsYWNlX2Nh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AgICAgICAvL9C/0YDQvtCx0LXQu9GLINC/0L7RgdC70LUg0LfQvdCw0LrQvtCyINC/0YDQtdC/0LjQvdCw0L3QuNGPCiAgICAgICAgICAgICAgICAgICAgICAnLyhb0LAt0Y/RkV0rKVxccysoKD860LB80L3QvilcXGIpL3VpJyA9PiAnJDEsICQyJ107IC8v0LfQvdCw0LrQuCDQv9GA0LXQv9C40L3QsNC90LjRjwoKICAgIGZvcmVhY2ggKCRzaW1wbGVSZXBsYWNlIGFzICRwYXR0ZXJuID0+ICRyZXBsYWNlbWVudCl7CiAgICAgICAgJHRleHQgPSBwcmVnX3JlcGxhY2UoJHBhdHRlcm4sICRyZXBsYWNlbWVudCwgJHRleHQpOwogICAgfQoKICAgICR0ZXh0ID0gZml4R3JhbW1hcignLyjRgSko0LTQtdGB0YwpL3VpJywgCiAgICAgICAgICAgICAgICAgICAgICAgIGZ1bmN0aW9uKCRtYXRjaGVzKXsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICRsZXR0ZXIgPSBjb3B5Q2FzZSgn0LcnLCAkbWF0Y2hlc1sxXSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAkd29yZCA9ICJ7JGxldHRlcn17JG1hdGNoZXNbMl19IjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiAkd29yZDsKICAgICAgICAgICAgICAgICAgICAgICAgfSwgJHRleHQpOwoKICAgICR0ZXh0ID0gZml4R3JhbW1hcignLyjQtyko0LTQtdC70LApKCg/OtGOfNC7fNC9KVxccyopL3VpJywgCiAgICAgICAgICAgICAgICAgICAgICAgIGZ1bmN0aW9uICgkbWF0Y2hlcyl7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAkbGV0dGVyID0gY29weUNhc2UoJ9GBJywgJG1hdGNoZXNbMV0pOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgJHdvcmQgPSAieyRsZXR0ZXJ9eyRtYXRjaGVzWzJdfXskbWF0Y2hlc1szXX0iOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuICR3b3JkOwogICAgICAgICAgICAgICAgICAgICAgICB9LCAkdGV4dCk7CgogICAgJHRleHQgPSBmaXhHcmFtbWFyKCcvKFvQsC3Rj9GRXSooPzrQtnzRiCkpKNGLKShb0LAt0Y/RkV0qKS91aScsIAogICAgICAgICAgICAgICAgICAgICAgICBmdW5jdGlvbiAoJG1hdGNoZXMpewogICAgICAgICAgICAgICAgICAgICAgICAgICAgJGxldHRlciA9IGNvcHlDYXNlKCfQuCcsICRtYXRjaGVzWzJdKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICR3b3JkID0gInskbWF0Y2hlc1sxXX17JGxldHRlcn17JG1hdGNoZXNbM119IjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiAkd29yZDsKICAgICAgICAgICAgICAgICAgICAgICAgfSwgJHRleHQpOwoKICAgIGVjaG8gJHRleHQ7Cj8+