<?php
//$text = "Кажется, нас обнаружили! Надо срочно уходить отсюда, пока не поздно. Бежим же скорее";
// Другие варианты для тестов
// $text = "Ну, прости меня! Не хотела я тебе зла сделать; да в себе не вольна была. Что говорила, что делала, себя не помнила.";
$text = "Идет гражданская война. Космические корабли повстанцев, наносящие удар с тайной базы, одержали первую победу, в схватке со зловещей Галактической Империей." ;
/* Делает первую букву предложения заглавной */
function makeFirstletterUppercase( $text ) {
function ( $matches ) {
$replacement = $matches [ 1 ] . $firstLetter ;
return $replacement ;
} ,
$text ) ;
return $text ;
}
function makeYodaStyleText( $text ) {
$sentences = preg_split ( '/[.?!]/ui' , $text , 0 , PREG_SPLIT_NO_EMPTY
) ; $yodaText = [ ] ;
foreach ( $sentences as $sentence ) {
$words = preg_split ( '/\\s+|[,;]/ui' , $sentence , 0 , PREG_SPLIT_NO_EMPTY
) ; $yodaSentence = implode ( ' ' , $words ) ; $yodaSentence = $yodaSentence . '.' ;
$yodaSentences [ ] = $yodaSentence ;
}
$yodaText = implode ( ' ' , $yodaSentences ) ; $yodaText = makeFirstletterUppercase( $yodaText ) ;
return $yodaText ;
}
$yodaText = makeYodaStyleText( $text ) ;
echo "Йода говорит: {$yodaText} \n " ;
PD9waHAKCmVycm9yX3JlcG9ydGluZygtMSk7Cm1iX2ludGVybmFsX2VuY29kaW5nKCd1dGYtOCcpOwoKLy8kdGV4dCA9ICLQmtCw0LbQtdGC0YHRjywg0L3QsNGBINC+0LHQvdCw0YDRg9C20LjQu9C4ISDQndCw0LTQviDRgdGA0L7Rh9C90L4g0YPRhdC+0LTQuNGC0Ywg0L7RgtGB0Y7QtNCwLCDQv9C+0LrQsCDQvdC1INC/0L7Qt9C00L3Qvi4g0JHQtdC20LjQvCDQttC1INGB0LrQvtGA0LXQtSI7Ci8vINCU0YDRg9Cz0LjQtSDQstCw0YDQuNCw0L3RgtGLINC00LvRjyDRgtC10YHRgtC+0LIKLy8gJHRleHQgPSAi0J3Rgywg0L/RgNC+0YHRgtC4INC80L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