<?php
$text = "Кажется, нас обнаружили! Надо срочно уходить отсюда, пока не поздно. Бежим же скорее!" ;
// Другие варианты для тестов
// $text = "Ну, прости меня! Не хотела я тебе зла сделать; да в себе не вольна была. Что говорила, что делала, себя не помнила.";
// $text = "Идет гражданская война. Космические корабли повстанцев, наносящие удар с тайной базы, одержали первую победу, в схватке со зловещей Галактической Империей.";
/*
function makeFirstLetterUppercase($text) {
$returnText = "";
$pattern = array(
"/^\w/u",
"/\.\s*\w/u"
);
$returnText = preg_replace_callback(
$pattern,
function ($matches) {
return mb_strtoupper($matches[0]);
},
$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 " ;
?>
PD9waHAKIAoJZXJyb3JfcmVwb3J0aW5nKC0xKTsKCW1iX2ludGVybmFsX2VuY29kaW5nKCd1dGYtOCcpOwoJIAoJJHRleHQgPSAi0JrQsNC20LXRgtGB0Y8sINC90LDRgSDQvtCx0L3QsNGA0YPQttC40LvQuCEg0J3QsNC00L4g0YHRgNC+0YfQvdC+INGD0YXQvtC00LjRgtGMINC+0YLRgdGO0LTQsCwg0L/QvtC60LAg0L3QtSDQv9C+0LfQtNC90L4uINCR0LXQttC40Lwg0LbQtSDRgdC60L7RgNC10LUhIjsKCQoJLy8g0JTRgNGD0LPQuNC1INCy0LDRgNC40LDQvdGC0Ysg0LTQu9GPINGC0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