PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
$sen="I have a pot, yes pot. DO u have pot? no pot. buy some pot more pot. I like pot. pot is now stop.";
$wordcounts = array();
$words = explode( " ", $sen );
foreach( $words as $word )
{
$word = strtolower( $word );
}
$wc = array_keys( $wordcounts );
sort( $wc );
echo $word;
?>
Output should be "pot" . but it shows only the last word..
waiting for reply !!!
*******************
Q2: Is there any function that can find even and odd number?
Look at str_word_count() combined with array_count_values() to count the number of instances of each word in a sentence or paragraph, and to get the most frequently used word.
$sen="I have a pot, yes pot. DO u have pot? no pot. buy some pot more pot. I like pot. pot is now stop.";
$words = array_count_values(str_word_count($sen,1));
$mostFrequentlyUsed = array_shift(array_keys($words));
$sen = "I have a pot, yes pot. DO u have pot? no pot. buy some pot more pot. I like pot. pot is now stop.";
$sen = preg_replace("/[^A-z ]/", '', $sen);
$words = explode( " ", $sen);
$wordcounts = array();
foreach( $words as $word )
{
$word = strtolower( $word );
if(isset($wordcounts[$word])) {
$wordcounts[$word]++;
} else {
$wordcounts[$word] = 1;
}
}
arsort($wordcounts);
$maxword = key($wordcounts);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
FYI, that's not division, it's the modulus (remainder) operator
Correct on the operator, however it is dividing by 2 and returning the remainder.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.