<?php
error_reporting(-1);
$text = "It seems that they found us? We must urgently leave here, before it's too late. Let's run fast!";
//$text = "Ну, прости меня! Не хотела я тебе зла сделать; да в себе не вольна была. Что говорила, что делала, себя не помнила.";
//$text = "Идет гражданская война. Космические корабли повстанцев, наносящие удар с тайной базы, одержали первую победу, в схватке со зловещей Галактической Империей.";
$editedText ="";
function makeYodaStyleText($text) {
$arrayOffers = preg_split('!(\\.)|(\\!)|(\\?)!ui',$text,-1,PREG_SPLIT_NO_EMPTY);
foreach ($arrayOffers as $key=>$value){
$arrayWords = preg_split("/[\s]+/",$value);
$arrayWords2 = array_reverse ($arrayWords);
$glue = " ";
$editedText .= implode($glue,$arrayWords2);
echo $editedText."1\n";
$editedText.=".";
}
$editedText = strtolower($text);
$editedText = preg_replace('/([а-яёА-ЯЁa-z0-9«]*)(\s)([\.\,\;\:\!\?\»])/iu', '$1$3', $editedText);
$editedText = preg_replace('/([\.\,\;\:\!\?\»])([а-яёА-ЯЁa-z0-9«])/iu', '$1 $2', $editedText);
return $text;
}
$yodaText = makeYodaStyleText($text);
echo "Йода говорит: {$yodaText}\n";
Warning: Undefined variable $editedText in /in/8jWC9 on line 15
us found they that seems It1
us found they that seems It.late too it's before here, leave urgently must We 1
us found they that seems It.late too it's before here, leave urgently must We .fast run Let's 1
Йода говорит: It seems that they found us? We must urgently leave here, before it's too late. Let's run fast!
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Warning: Undefined variable $editedText in /in/8jWC9 on line 15
us found they that seems It1
us found they that seems It.late too it's before here, leave urgently must We 1
us found they that seems It.late too it's before here, leave urgently must We .fast run Let's 1
Йода говорит: It seems that they found us? We must urgently leave here, before it's too late. Let's run fast!
Notice: Undefined variable: editedText in /in/8jWC9 on line 15
us found they that seems It1
us found they that seems It.late too it's before here, leave urgently must We 1
us found they that seems It.late too it's before here, leave urgently must We .fast run Let's 1
Йода говорит: It seems that they found us? We must urgently leave here, before it's too late. Let's run fast!