Home > Backend Development > PHP Tutorial > felayman-php_自定义函数过滤指定字符

felayman-php_自定义函数过滤指定字符

WBOY
Release: 2016-06-13 11:54:02
Original
767 people have browsed it

felayman------php_自定义函数过滤指定字符

<pre code_snippet_id="279207" snippet_file_name="blog_20140407_1_2389317" name="code" class="php"><?php /** * Created by PhpStorm. * User: FelayMan * Date: 14-4-7 * Time: 下午5:09 */    function filter_str($str){        $arr = array('图书','明日科技','软件','变成词典','词典');        //implode将数组连接成字符串        $repstr = implode(',',$arr);        echo $repstr;        //preg_match将会在$repstr中检索$str,如果出现则会停止检索        if(preg_match("/$str/",$repstr)){            echo "<script>                alert('您使用了禁用词语');                window.location.href='filter_string.php5';                ";        }else{            echo $str;        }    }    function filter_words($str){        //假设我无法在留言板中输入中国        $words = "中国";        if(preg_match("/$words/",$str)){            echo "<script>                alert('你的留言者包含了危险词语');                window.location.href='filter_string.php5';                </script>";        }else{            echo "$str";        }    }    if(!empty($_POST['sub'])){       // filter_str($_POST['content']);        filter_words($_POST['content']);    }?>                <title>自定义函数过滤器</title>        <meta charset="utf-8">            
Copy after login
请留言:


Copy after login
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