I have a long text (3600 sentences) and I want to change the order of random sentences. There are some simple PHP script that can change the order of sentences?
You can accomplish it like this. Explode a string on the end of a sentence e.g full stop. Shuffle the array using the shuffle function. Then implode the string, adding the full stops back.
The output will be something like:
Hello, this is one sentence. This is a fifth. This is a forth. This is a second.. THis is a third
$sentences = 'Hello, this is one sentence. This is a second. THis is a third. This is a forth. This is a fifth.';
$sentencesArray = explode('.', $sentences);
array_filter($sentencesArray);
shuffle($sentencesArray);
$sentences = implode('.', $sentencesArray);
var_dump($sentences);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With