Count And Display Words In A String Into Array Php Sentence Word

RegisterLogin
Count And Display Words In A String Into Array Php Sentence Word
Post Description: Count And Display Words In A String Into Array Php Sentence Word
Tags: Count, And, Display, Words, In, A, String, Into, Array, Php, Sentence, Word
This Post Was Posted On Feb 29, 2008 By web hosting #1298
ok.

lets say i have this string:

$string = 'simple sentence with five words';


so if you want to break this sentence into an array you can do this:

$words = explode(' ', $string );


now if you want to display it in an array you can do this:

for( $i = 0; $i < count($words); ++$i )
echo $i.'. '.$words[$i].'
';


OUTPUT:
0. simple
1. sentence
2. with
3. five
4. words
©2012 Webune Forums - Sun Dec 16, 2012 11:12 am
Powered by: Webune Forums V3