PHP Filter blacklist keyword method _php tips

Source: Internet
Author: User

This article describes the PHP filtering blacklist keyword method. Share to everyone for your reference. The implementation methods are as follows:

Keyword filtering is very simple to filter the content to exist in an array or document, and then the user submitted when we preg_match or istrpos judgment can be resolved, the specific methods are as follows.

The instance code is as follows:

Copy Code code as follows:
Filter blacklist keyword functions
function Check_ ($data) {
$keywords = "Are you the Great God | hello | to die";
if (Preg_match ("/$keywords/I", $data)) {
Return
}else{
return $data;
}
}

Keywords are stored in such a form as txt,txt files: | gambling machine | selling Blood | sell the Kidney | Sell the Organ | Cornea, the code is as follows:
Copy Code code as follows:
<?php
function Filter_word ($STR, $fileName)
{
if (!) ( $words = file_get_contents ($fileName))) {
Die (' file read error! ');
}
$str = Strtolower ($STR);
Var_dump ($words);
$word = Preg_replace ("/[1,2,3] | /i ", ', $words);
$wor = substr ($word, 0,-1);
$w = Preg_replace ("|/|i", '/', $word);
echo "<pre>";
Var_dump ($w);
$words = "Aaa|bbb|ccc|ddd|eee";
$matched = preg_replace ('/'. $word. /I ', ' * * * ', $string);
return $matched;
}

$content = "<a href= ' > I want to aaafsdfbbb</a>";
if ($result = Filter_word ($content, './words.txt ')) {
echo $result;
echo "Replace success";
}else{
echo "Replace failed!";
?>

I hope this article will help you with your PHP program design.

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.