php - How do I convert a string to an associative array of its keywords -
take string example: "will see in london tomorrow , kent day after tomorrow".
how convert associative array contains keywords keys, whilst preferably missing out common words, this:
array ( [tomorrow] => 2 [london] => 1 [kent] => 1)
any appreciated.
using blacklist of words not included
$str = 'will see in london tomorrow , kent day after tomorrow'; $skip_words = array( 'in', 'the', 'will', 'see', 'and', 'day', 'you', 'after' ); // words in sentence aren't skipped , count values $words = array_count_values( array_diff( explode( ' ', $str ), $skip_words ) ); print_r( $words );
Comments
Post a Comment