Quote:
Originally Posted by Brujah
$sentences = preg_split( '/\.|\!+/', $s);
array_map( 'trim', $sentences);
echo implode( '. ', $sentences );
|
The code above won't work because:
1) it doesn't actually shuffle sentences;
2) it doesn't split sentences that end with "..." and "?";
3) the result of array_map() will be lost;
4) all exclamation marks will be replaced with dots.
So here is the fixed version:
preg_match_all('/.*?[\?|\.\.\.|\.|\!]+/s', $s, $sentences);
$sentences[0] = array_map('trim', $sentences[0]);
shuffle($sentences[0]);
echo implode(' ', $sentences[0]);