View Single Post
Old 05-12-2012, 09:31 AM  
Brujah
Beer Money Baron
 
Brujah's Avatar
 
Industry Role:
Join Date: Jan 2001
Location: brujah / gmail
Posts: 22,157
I like this version so far:

Code:
$string = <<<EOS
Lorem ipsum is the most common form of "Greeking". However more and more people are sick and tired of using the same sample text over and over again. Also lorem ipsum is in latin and it may not always be the best choice. We tried to have text generated in some of the most widely used languages but if you are in desperate need of random text in your own language, send us an email and we'll add it here.
Adding a few extra examples... you mean like this? Hmm, what the hell?!!!
EOS;

preg_match_all( '/[^.?!]+[.?!]+/m', $string, $matches );
$sentences = array_map( 'trim', $matches[0] );
shuffle( $sentences );
$sentences = array_map( 'ucfirst', $sentences );
echo implode( ' ', $sentences );
This kept the mix of punctuation and any number of it together, and in case of a fragment with lowercase first letter it'll fix that.

Outputs:
However more and more people are sick and tired of using the same sample text over and over again. We tried to have text generated in some of the most widely used languages but if you are in desperate need of random text in your own language, send us an email and we'll add it here. You mean like this? Adding a few extra examples... Hmm, what the hell?!!! Lorem ipsum is the most common form of "Greeking". Also lorem ipsum is in latin and it may not always be the best choice.
__________________

Last edited by Brujah; 05-12-2012 at 09:45 AM.. Reason: fixing ucfirst
Brujah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote