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;
}
?>
$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;
}
?>
Comments
Post a Comment