PHP - How to isolate the first 10 words out of a large text php isolate first 10 words from large text, implode array
Let's say you have a web form that inputs large texts and you want your processing script (php in this case) to create an introduction text which will contain the first 10 words from the large text, for example. Here's how to do it:
PHP - How to isolate the first 10 words out of a large text
$large_text = $_POST['main_text']; $array = explode(" ",$large_text); $intro_lenght = 10; for ($i =0; $i < $intro_lenght; $i ++) { $intro_text .= $array[$i].' '; } /* $intro_text will now be "large_text_word0 large_text_word1 .....large_text_word9 " 10 words with space after lat word (which can easily be bypassed with an if function for $i variable) */ echo $intro_text;
?>
Now you have an introduction text that contains only the first 10 words from inputed large text.
I know it is probably not the best way to do this, but it's a start.
Designed and developed by Andrei Manescu. Optimized for Mozilla Firefox.
Copyright 2007 Andrei Manescu
All trademarks and copyrights on this page are owned by their respective owners. Comments are owned by those who posted them.