<?php
//$text = "Кажется, нас обнаружили! Надо срочно уходить отсюда, пока не поздно. Бежим же скорее!";
// Другие варианты для тестов
// $text = "Ну, прости меня! Не хотела я тебе зла сделать; да в себе не вольна была. Что говорила, что делала, себя не помнила.";
$text = "Идет гражданская война. Космические корабли повстанцев, наносящие удар с тайной базы, одержали первую победу, в схватке со зловещей Галактической Империей." ;
/* Делает первую букву в строке заглавной */
function makeFirstLetterUppercase( $text ) {
$returnText = "" ;
"/^\w/u" ,
"/\.\s*\w/u"
) ;
$pattern ,
function ( $matches ) {
} ,
$text
) ;
return $returnText ;
}
function makeYodaStyleText( $text ) {
$result = '' ;
$yodaSentence = "" ;
$splitSentence = array ( ) ; $wordsSentence = array ( ) ; // $pattern = "/\b[а-яА-Я-]{1,}\b/u";
$splitSentence = preg_split ( "/[.!?;]/u" , $text , - 1 , PREG_SPLIT_NO_EMPTY
) ; foreach ( $splitSentence as $sentence ) {
$wordsSentence = preg_split ( "/[\s,]+/u" , $sentence , - 1 , PREG_SPLIT_NO_EMPTY
) ; $yodaSentence = implode ( " " , $wordsSentence ) ; $yodaSentence = makeFirstLetterUppercase( $yodaSentence ) . ". " ;
$result = $result . $yodaSentence ;
}
return $result ;
}
$yodaText = makeYodaStyleText( $text ) ;
echo "Йода говорит: {$yodaText} \n " ;
?>
PD9waHAKIAoJZXJyb3JfcmVwb3J0aW5nKC0xKTsKCW1iX2ludGVybmFsX2VuY29kaW5nKCd1dGYtOCcpOwoJIAoJLy8kdGV4dCA9ICLQmtCw0LbQtdGC0YHRjywg0L3QsNGBINC+0LHQvdCw0YDRg9C20LjQu9C4ISDQndCw0LTQviDRgdGA0L7Rh9C90L4g0YPRhdC+0LTQuNGC0Ywg0L7RgtGB0Y7QtNCwLCDQv9C+0LrQsCDQvdC1INC/0L7Qt9C00L3Qvi4g0JHQtdC20LjQvCDQttC1INGB0LrQvtGA0LXQtSEiOwoJCgkvLyDQlNGA0YPQs9C40LUg0LLQsNGA0LjQsNC90YLRiyDQtNC70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