View Single Post
Old 05-12-2012, 01:25 AM  
just a punk
So fuckin' bored
 
just a punk's Avatar
 
Industry Role:
Join Date: Jun 2003
Posts: 32,391
:2cents

Quote:
Originally Posted by Brujah View Post
$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]);
__________________
Obey the Cowgod
just a punk is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote