Sunday, September 16, 2012

count number of word from a string in php

<?php
$str = "extract word from a sring using php";
//before
$extractword= str_word_count($str);
$extword=explode(" ",$str);
//count word from string
echo count($extword);
echo "total word in a string is =$extractword<br>";
// after
$couter=1;
foreach($extword as $word){
echo "$couter  ".$word."<br>";
$couter=$couter+1;


}
?>

No comments:

Post a Comment