Line Feed-[PHP] when I use PHP to calculate a txt word in pure English, why? [Resolved]

Source: Internet
Author: User
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,trimThe function removes the spaces on both sides (rn), I feel the problem is here.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.