婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > PHP使用正則表達式實現過濾非法字符串功能示例

PHP使用正則表達式實現過濾非法字符串功能示例

熱門標簽:合肥外呼系統app 哈爾濱400電話辦理到易號網 智能外呼電銷系統 拉薩打電話機器人 高識別電銷機器人 寶安400電話辦理 電銷機器人-快迭智能 h5 地圖標注 沈陽人工智能電銷機器人公司

本文實例講述了PHP使用正則表達式實現過濾非法字符串功能。分享給大家供大家參考,具體如下:

一、代碼

1、index.php

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
html xmlns="http://www.w3.org/1999/xhtml">
head>
meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
title>過濾留言板中的非法字符/title>
style type="text/css">
!--
body {
  margin-left: 0px;
  margin-top: 0px;
  margin-right: 0px;
  margin-bottom: 0px;
}
-->
/style>/head>
body>
table width="1002" height="585" border="0" align="center" cellpadding="0" cellspacing="0">
 tr>
  td width="379" height="226">nbsp;/td>
  td width="445">nbsp;/td>
  td width="178">nbsp;/td>
 /tr>
   form id="form1" name="form1" method="post" action="index_ok.php">
 tr>
  td height="260">nbsp;/td>
  td align="center" valign="top">table width="430" border="1" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#99CC67">
   tr>
    td width="81" height="30" align="right" bgcolor="#FFFFFF">發布主題:/td>
    td width="307" align="left" bgcolor="#FFFFFF">input name="title" type="text" id="title" size="30" />/td>
   /tr>
   tr>
    td align="right" bgcolor="#FFFFFF">發布內容:/td>
    td align="left" bgcolor="#FFFFFF">textarea name="content" cols="43" rows="13" id="content">/textarea>/td>
   /tr>
  /table>/td>
  td>nbsp;/td>
 /tr>
 tr>
  td height="99">nbsp;/td>
  td align="center" valign="top">table width="315" height="37" border="0" cellpadding="0" cellspacing="0">
   tr>
    td width="169" align="center">input type="image" name="imageField" src="images/bg1.JPG" />/td>
    td width="146" align="center">input type="image" name="imageField2" src="images/bg3.JPG" onclick="form.reset();return false;" />/td>
   /tr>
  /table>/td>
  td>nbsp;/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>
head>
meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
title>過濾留言板中的非法字符/title>
style type="text/css">
!--
body {
  margin-left: 0px;
  margin-top: 0px;
  margin-right: 0px;
  margin-bottom: 0px;
}
.STYLE1 {
  font-size: 12px;
  color: #855201;
}
-->
/style>/head>
body>
table width="1002" height="585" border="0" align="center" cellpadding="0" cellspacing="0">
 tr>
  td width="400" height="226">nbsp;/td>
  td width="406">nbsp;/td>
  td width="196">nbsp;/td>
 /tr>
   form id="form1" name="form1" method="post" action="index_ok.php">
 tr>
  td height="260">nbsp;/td>
  td align="left" valign="top">p class="STYLE1">發布主題:?php echo $titles;?>/p>
   p class="STYLE1">發布內容:?php echo $contents;?>/p>/td>
  td>nbsp;/td>
 /tr>
 tr>
  td>nbsp;/td>
  td align="center" valign="top">nbsp;/td>
  td>nbsp;/td>
 /tr>
 /form>
/table>
/body>
/html>

二、運行結果

發布主題:****
發布內容:****客 ****包

PS:這里再為大家提供2款非常方便的正則表達式工具供大家參考使用:

JavaScript正則表達式在線測試工具:
http://tools.jb51.net/regex/javascript

正則表達式在線生成工具:
http://tools.jb51.net/regex/create_reg

更多關于PHP相關內容感興趣的讀者可查看本站專題:《php正則表達式用法總結》、《php程序設計安全教程》、《php安全過濾技巧總結》、《PHP數組(Array)操作技巧大全》、《PHP基本語法入門教程》、《php字符串(string)用法總結》及《php+mysql數據庫操作入門教程》

希望本文所述對大家PHP程序設計有所幫助。

您可能感興趣的文章:
  • PHP常用正則表達式精選(推薦)
  • PHP正則表達式筆記與實例詳解
  • PHP利用正則表達式實現手機號碼中間4位用星號(*)替換顯示功能
  • 史上最全的PHP正則表達式(手機號需要加上177-***)
  • PHP preg_match實現正則表達式匹配功能【輸出是否匹配及匹配值】
  • PHP手機號碼及郵箱正則表達式實例解析

標簽:巴中 山東 威海 梅州 成都 林芝 泰州 張家口

巨人網絡通訊聲明:本文標題《PHP使用正則表達式實現過濾非法字符串功能示例》,本文關鍵詞  PHP,使用,正則,表達式,實現,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《PHP使用正則表達式實現過濾非法字符串功能示例》相關的同類信息!
  • 本頁收集關于PHP使用正則表達式實現過濾非法字符串功能示例的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 东阳市| 班戈县| 西藏| 江达县| 娱乐| 无为县| 长乐市| 汶上县| 错那县| 青岛市| 广平县| 土默特右旗| 甘泉县| 西峡县| 安宁市| 蕲春县| 红安县| 临海市| 彭泽县| 区。| 车险| 拉萨市| 台东市| 台州市| 墨竹工卡县| 来宾市| 通榆县| 海兴县| 富顺县| 湘西| 盘锦市| 马鞍山市| 六枝特区| 永登县| 离岛区| 安多县| 六枝特区| 平江县| 新建县| 朝阳市| 壤塘县|