Count how often the word occurs in the text in PHP -


In PHP I need to load a file and get all the words and resonate the number of words and each word shows In the text, (I also need to show them in the most commonly used words in the order downward) ★ ✩

itemprop = "text">

Here's an example:

  $ text = "A great text lesson. If you are in Unicode, think about it. Rchha will. " // $ word = str_word_count ($ text, 1); // Use this function if you only want the word ASCII $ = utf8_str_word_count ($ text, 1); // If you take care about i18n $ instance = array_count_values ​​($ word), use this function; Arsort ($ frequency); Echo '& lt; Pre & gt; '; Print_r ($ frequency); Echo & lt; / Pre & gt; '; 2 [if] = & gt; 1 [About]  1 in [in] => 1 [Unicode] = & gt; 1 [thinking] => 1 [to] = & gt; 1 [many] => 1 [únÌcÕdë] = & gt; 1 [text] = & gt; 1 [anything] => 1 [A] = & gt; 1)  

and utf8_str_word_count () function, if you need it:

  function Utf8_str_word_count ($ string, $ format = 0, $ charlist = null) {$ result = array (); If (preg_match_all ( '~ [\ p {L} \ p {Mn} \ p {Pd} \' \ x {2019} '. Preg_quote ($ charlist,' ~ ').'] + ~ U ', $ string , $ Result) & gt; 0) {if (array_key_exists (0, $ result) === true) {$ result = $ result [0]; }} If ($ format == 0) {$ result = count ($ result); } Return result; }  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -