RE: Splitting long text

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



[snip]
I have a requirement to take a large amount of 
text, a story submitted to a competition, and 
split into displayable chunks of 600 words each.

I'd like some feedback on the best way to this.
[/snip]

There are many ways to skin this cat Skip but you can start with the
basics of using explode() and implode(). For instance, count all of the
words;

function countwords($str) {
   return count(array_filter(explode(' ', $str)));
} 


// Example Usage: 
$test = "This has four words."; 
echo "There are " . countwords($test) . " words in that '$test'"; 

Check out the usage of array_filter(), it will get rid of multiple
spaces between words. You will have to do more to filter out new lines
between paragraphs, but this should get you started.

Since explode is an array you can then implode 600 word chunks of text.

http://www.php.net/explode
http://www.php.net/implode
http://www.php.net/array_filter

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux