Fri Feb 29, 2008 12:01 pm - Count And Display Words In A String Into Array Php Sentence Word
#1298
Count And Display Words In A String Into Array Php Sentence Word
ok.
lets say i have this string:
so if you want to break this sentence into an array you can do this:
now if you want to display it in an array you can do this:
OUTPUT:
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].'
';
echo $i.'. '.$words[$i].'
';
OUTPUT:
0. simple
1. sentence
2. with
3. five
4. words
1. sentence
2. with
3. five
4. words
author: web hosting