本文实例讲述了服务器端编程语言(专业超文本预处理器的缩写)使用正则表达式实现过滤非法字符串功能。分享给大家供大家参考,具体如下:
一、代码
1、index.php
!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN ' ' http://www .w3。org/TR/XHTML 1/DTD/XHTML 1-Transitional。DTD ' html xmlns=' http://www .w3。org/1999/XHTML ' hearteta http-equiv=' Content-Type ' Content=' text/html;字符集=GB 2312/标题过滤留言板中的非法字符/titlestyle type='text/css '!-body { margin-left : 0px;边距-top : 0px;右边距: 0px边距-底部: 0px}-/style/head dytable width=' 1002 ' height=' 585 ' border=' 0 ' align=' center '单元格填充=' 0 '单元格间距=' 0 ' tr TD width=' 379 ' height=' 226 '/TD TD width=' 445 '/TD TD TD width=' 178 '/TD/tr form id=' form 1 ' name=' form 1 ' method=' post ' action=' index _ ok。PHP ' tr TD高度=' 260 '/TD TD对齐发布主题:/TD TD宽度=' 307 ' align=' left ' bgcolor=' # FFFFFF '输入名称=' title ' type=' text ' id=' title ' size=' 30 '/TD/tr TD align=' right ' bgcolor=' # FFFFFF '发布内容:/TD TD align=' left ' bgcolor=' # FFFFFF ' text area name=' content ' cols=' 43 ' row=' 13 ' id=' content '/text area/TD/tr/table/TD/TD/tr TD高度=' 99 '/TD TD TD align=' center ' valgn=' top '表格宽度=' 315 '高度=' 37 '边框=' 0 '单元格填充=' 0 '单元格间距=' 0 ' tr TD宽度=' 169 ' align=' center 'JPG '/TD TD宽度=146 ' align=' center '输入类型=' image ' name=' image field 2 ' src=' http : images/bg3 . JPG。reset();返回false '/TD/tr/table/TD/TD/tr/form/table/body/html 2、index_ok.php
?PHP $ title=$ _ POST[title];$ content=$ _ POST[content];$ str=' * * * $ titles=preg _ replace(/(黑客)|(抓包)|(监听)/',$str,$ title);$contents=preg_replace('/(黑客)|(抓包)|(监听)/',$str,$ content);html health eta http-equiv=' Content-Type ' Content=' text/html;字符集=GB 2312/标题过滤留言板中的非法字符/titlestyle type='text/css '!-body { margin-left : 0px;边距-top : 0px;右边距: 0px边距-底部: 0px} .STYLe 1 { font-size : 12pxcolor : # 855201 }-/style/head dytable width=' 1002 ' height=' 585 ' border=' 0 ' align=' center '单元格填充=' 0 '单元格间距=' 0 ' tr TD width=' 400 ' height=' 226 '/TD TD width=' 406 '/TD TD TD width=' 196 '/TD/tr form id=' form 1 ' name=' form 1 ' method=' post ' action=' index _ ok。PHP ' tr TD高度=' 260 '/TD TD对齐发布主题:php echo $ titles?/p p class='STYLE1 '发布内容:php echo $目录;/p/TD/TD/TD/tr/tr TD/TD align=' center ' valign=' top '/TD/TD/tr/form/table/body/html二、运行结果
发布主题:****发布内容:****客****包
PS:这里再为大家提供2款非常方便的正则表达式工具供大家参考使用:
Java脚本语言正则表达式在线测试工具:http://工具。JB 51。net/regex/JavaScript
正则表达式在线生成工具:http://工具。JB 51。net/regex/create _ reg
更多关于服务器端编程语言(专业超文本预处理器的缩写)相关内容感兴趣的读者可查看本站专题: 《php正则表达式用法总结》 、 《php程序设计安全教程》 、 《php安全过滤技巧总结》 、 《PHP数组(Array)操作技巧大全》 、 《PHP基本语法入门教程》 、 《php字符串(string)用法总结》 及《php+mysql数据库操作入门教程》
希望本文所述对大家服务器端编程语言(专业超文本预处理器的缩写)程序设计有所帮助。