The code is as follows: {code ...} output result: {code ...} I do not understand why the two words to judge into a word, txt is opened with sublime and set the encoding for the UTF-8, did not use the computer's built-in text document tool to open and edit, in addition, when filtering punctuation marks, there are also some... the code is as follows:
$ Value) {// filter out words such as I'll, you're, masters's if (strpos ($ value ,''')! = False | strpos ($ value ,"'")! = False) {continue;} // filter out empty if (empty ($ value) === true) {continue;} if (array_key_exists ($ value, $ res )) {$ res [$ value] ++;} else {$ res [$ value] = 1 ;}/// sort array_multisort ($ res, SORT_DESC, SORT_NUMERIC ); return $ res ;}
Output result:
array( [repression] => 1 [thoroughness] => 1 [bleached] => 1 [tow] => 1 [inspired] => 1 [uniformwell] => 1 [panamas] => 1 [capswhen] => 1)
I do not understand why the two words to judge into a word, txt is opened with sublime and set the encoding for the UTF-8, did not use the computer's built-in text document tool to open and edit, in addition, when you filter punctuation marks, you can also filter out rn, but it does not work, so the code is removed. Why is this problem solved and how to avoid it?
Reply content:
The code is as follows:
$ Value) {// filter out words such as I'll, you're, masters's if (strpos ($ value ,''')! = False | strpos ($ value ,"'")! = False) {continue;} // filter out empty if (empty ($ value) === true) {continue;} if (array_key_exists ($ value, $ res )) {$ res [$ value] ++;} else {$ res [$ value] = 1 ;}/// sort array_multisort ($ res, SORT_DESC, SORT_NUMERIC ); return $ res ;}
Output result:
array( [repression] => 1 [thoroughness] => 1 [bleached] => 1 [tow] => 1 [inspired] => 1 [uniformwell] => 1 [panamas] => 1 [capswhen] => 1)
I do not understand why the two words to judge into a word, txt is opened with sublime and set the encoding for the UTF-8, did not use the computer's built-in text document tool to open and edit, in addition, when you filter punctuation marks, you can also filter out rn, but it does not work, so the code is removed. Why is this problem solved and how to avoid it?
Your problem should be caused by not handling line breaks (and carriage return) and replacing those filter characters with '', which should be replaced''
$ Value) {// filter out empty if (! $ Value) {continue;} // filter out words such as I'll, you're, masters's if (strpos ($ value ,''')! = False | strpos ($ value ,"'")! = False) {continue;} if (array_key_exists ($ value, $ res) {$ res [$ value] ++ ;} else {$ res [$ value] = 1 ;}// sort array_multisort ($ res, SORT_DESC, SORT_NUMERIC); return $ res ;}
I don't know what the strings look like in your file,trim
The function removes the spaces on both sides (rn
), I feel the problem is here.