- Forums
- PHP
- Count And Display Words In A String Into Array Php Sentence Word
This Page Contains information about Count And Display Words In A String Into Array Php Sentence Word By wallpaperama in category PHP with 3 Replies. [1088], Last Updated: Sat May 18, 2024
wallpaperama
Fri Feb 15, 2008
3 Comments
4612 Visits
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