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.