Jump to content

Searching for repeated words in string :)


lopez86100

Recommended Posts

I've got big text in a string. I don't know how to do that: I want to find 3 words that are most repeated in this string. I'm creating search engine for my website so I need it. Can anyone help me. Maybe there are some ready solutions (someone has created it before me) but I can't find it. please... please.... help me :) :)
Link to comment
https://forums.phpfreaks.com/topic/32410-searching-for-repeated-words-in-string/
Share on other sites

I  would explode the sentance by the space, causing each individual word to be placed into an array, then you can filter out words that are smaller than 3 letters or something and then you can sort the array.  After the array is sorted, you can easily find which are repeated the most.
As the above poster suggests, use the [url=http://www.php.net/explode]explode()[/url] function to get all the words in the sentence into an array, then use the function [url=http://www.php.net/array_count]array_count()[/url] to get the frequency of each word in another array. You can then sort that array.

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.