Question about keyword filtering by strpos function

Source: Internet
Author: User
Question about keyword filtering by strpos function keyword This post was last edited by ron_xin from 2014-10-2514: 31: 16 & lt ;? Phpheader (Content-type: & nbsp; texthtml; & nbsp; charsetutf-8); * & nbsp; use the strpos function in PHP to filter keywords.

This post was last edited by ron_xin at 14:31:16




Header ("Content-type: text/html; charset = utf-8 ");

/* Use the strpos function in PHP to filter keywords */
// Keyword filtering function

Function keyWordCheck ($ content ){
// Remove the blank
$ Str = trim ($ content );
// Read the keyword text
$ KeyWords = @ file_get_contents ('Keywords. TXT ');
// Convert to an array

$ Arr = explode (",", $ keyWords );

// Traversal detection

$ K = count ($ arr );
Echo $ k;
Echo"
";

For ($ I = 0, $ k; $ I <$ k; $ I ++ ){
Echo $ str;
Echo "keyword being detected:". $ arr [$ I];
Echo"
";

// Skip this loop if the array element is null
// If ($ arr [$ I] = '')
//{
// Continue;
//}

Echo stripos ($ str, $ arr [$ I]);

// If a keyword is detected, the matching keyword is returned and the running is terminated.
// If (strpos ($ str, $ arr [$ I])> = 0 ){
// $ I = $ k;
// Return $ arr [$ I];
// Echo "detected Keywords:". $ arr [$ I];
// Echo"
";
//}
}
// If no keyword is detected, false is returned.
Return false;
}

$ Content = 'here is the Zhuhai text content WWW to be published... ';

// Filter keywords
$ KeyWord = keyWordCheck ($ content );
Echo $ keyWord;


?>


Echo stripos ($ str, $ arr [$ I]); // no detected
Echo stripos ($ str, "Zhuhai"); // detected

KeyWords. TXT content
Zhuhai, Central, Macao, and airport

------------------------------
4
Here is the Zhuhai text content WWW to be published... Keyword being detected :? Zhuhai
Here is the Zhuhai text content WWW to be published... Keyword being detected: Central
Here is the Zhuhai text content WWW to be published... Keyword being checked: Macao
Here is the Zhuhai text content WWW to be published... Keyword being checked: Airport


Extremely stuffy

------ Solution ----------------------
BOM header length, but not displayed
You can change the keyWords. TXT file to the following:
, Zhuhai, Central, Macau, airport

That is, the front is a comma.

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.