Home > Backend Development > PHP Tutorial > PHP uses preg_replace and preg_match to filter sensitive words_PHP tutorial

PHP uses preg_replace and preg_match to filter sensitive words_PHP tutorial

WBOY
Release: 2016-07-21 14:58:03
Original
967 people have browsed it

PHP uses preg_replace and preg_match to filter sensitive words

Code 1:

Copy to ClipboardLiehuo.Net CodesQuoted content: [www.bkjia.com] $badstring="tmd|damn|TNND|her motherfucker";
$string="What did you tmd say, her motherfucker is not a human being";
echo preg_replace(" /$badstring/i",'',$string);
?>

Code 2:

Copy to ClipboardLiehuo.Net CodesQuoted content: [www.bkjia.com]
$badkey = "sensitive word|sensitive word B|sensitive word C";

$string = "I do not contain sensitive words, I want to publish";

if(preg_match("/$badkey/i",$string)){

echo "Sorry, it contains sensitive characters and is not allowed to be published";

}else {

//do something...
echo "Bangkejia Tips: You can use www.bkjia.com";
}

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/363924.htmlTechArticlePHP uses preg_replace and preg_match to filter sensitive words Code 1: Copy to Clipboard Quoted content: [www.veryhuo.com ] ?php $badstring=tmd|Damn|TNND|Her mother-in-law; $string=What did you tmd say...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template