PHP簡單字符串過濾方法示例
本文實(shí)例講述了PHP簡單字符串過濾方法。分享給大家供大家參考,具體如下:
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
<title>PHP字符串的過濾方法</title>
</head>
<body>
<?php
function strFilter($str){
//特殊字符的過濾方法
$str = str_replace('`', '', $str);
$str = str_replace('·', '', $str);
$str = str_replace('~', '', $str);
$str = str_replace('!', '', $str);
$str = str_replace('!', '', $str);
$str = str_replace('@', '', $str);
$str = str_replace('#', '', $str);
$str = str_replace('$', '', $str);
$str = str_replace('¥', '', $str);
$str = str_replace('%', '', $str);
$str = str_replace('^', '', $str);
$str = str_replace('……', '', $str);
$str = str_replace('&', '', $str);
$str = str_replace('*', '', $str);
$str = str_replace('(', '', $str);
$str = str_replace(')', '', $str);
$str = str_replace('(', '', $str);
$str = str_replace(')', '', $str);
$str = str_replace('-', '', $str);
$str = str_replace('_', '', $str);
$str = str_replace('——', '', $str);
$str = str_replace('+', '', $str);
$str = str_replace('=', '', $str);
$str = str_replace('|', '', $str);
$str = str_replace('\\', '', $str);
$str = str_replace('[', '', $str);
$str = str_replace(']', '', $str);
$str = str_replace('【', '', $str);
$str = str_replace('】', '', $str);
$str = str_replace('{', '', $str);
$str = str_replace('}', '', $str);
$str = str_replace(';', '', $str);
$str = str_replace(';', '', $str);
$str = str_replace(':', '', $str);
$str = str_replace(':', '', $str);
$str = str_replace('\'', '', $str);
$str = str_replace('"', '', $str);
$str = str_replace('“', '', $str);
$str = str_replace('”', '', $str);
$str = str_replace(',', '', $str);
$str = str_replace(',', '', $str);
$str = str_replace('<', '', $str);
$str = str_replace('>', '', $str);
$str = str_replace('《', '', $str);
$str = str_replace('》', '', $str);
$str = str_replace('.', '', $str);
$str = str_replace('。', '', $str);
$str = str_replace('/', '', $str);
$str = str_replace('、', '', $str);
$str = str_replace('?', '', $str);
$str = str_replace('?', '', $str);
//防sql防注入代碼的過濾方法
$str = str_replace('and','',$str);
$str = str_replace('execute','',$str);
$str = str_replace('update','',$str);
$str = str_replace('count','',$str);
$str = str_replace('chr','',$str);
$str = str_replace('mid','',$str);
$str = str_replace('master','',$str);
$str = str_replace('truncate','',$str);
$str = str_replace('char','',$str);
$str = str_replace('declare','',$str);
$str = str_replace('select','',$str);
$str = str_replace('create','',$str);
$str = str_replace('delete','',$str);
$str = str_replace('insert','',$str);
$str = str_replace('or','',$str);
return trim($str);
}
$cont = ' ?”?;onestopweb.cn and update //\ as chaoyi 》、 ';
echo '開始['.strFilter($cont).']結(jié)束';
?>
</body>
</html>
效果圖如下:

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php安全過濾技巧總結(jié)》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP基本語法入門教程》、《php操作office文檔技巧總結(jié)(包括word,excel,access,ppt)》、《php日期與時間用法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設(shè)計(jì)有所幫助。
- 幾個有用的php字符串過濾,轉(zhuǎn)換函數(shù)代碼
- php字符串過濾與替換小結(jié)
- 詳解PHP函數(shù) strip_tags 處理字符串缺陷bug
- php使用strip_tags()去除html標(biāo)簽仍有空白的解決方法
- PHP strip_tags保留多個HTML標(biāo)簽的方法
- PHP strip_tags() 去字符串中的 HTML、XML 以及 PHP 標(biāo)簽的函數(shù)
- PHP關(guān)于htmlspecialchars、strip_tags、addslashes的解釋
- PHP函數(shù)strip_tags的一個bug淺析
- PHP strip_tags()去除HTML、XML以及PHP的標(biāo)簽介紹
- php 去除html標(biāo)記--strip_tags與htmlspecialchars的區(qū)別詳解
- php字符串過濾strip_tags()函數(shù)用法實(shí)例分析
相關(guān)文章
php中json_decode()和json_encode()的使用方法
json_decode對JSON格式的字符串進(jìn)行編碼而json_encode對變量進(jìn)行 JSON 編碼,需要的朋友可以參考下2012-06-06
PHP+MySQL+sphinx+scws實(shí)現(xiàn)全文檢索功能詳解
這篇文章主要介紹了PHP+MySQL+sphinx+scws實(shí)現(xiàn)全文檢索功能,詳細(xì)分析了sphinx、scws的下載安裝、配置、數(shù)據(jù)庫創(chuàng)建及全文檢索功能的相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-08-08
PHP性能分析工具xhprof的安裝使用與注意事項(xiàng)
xhprof 是一款Facebook工程師開發(fā)和維護(hù)的一款PHP性能分析、調(diào)試工具,相較于xdebug要更輕量,更節(jié)省資源,強(qiáng)烈推薦大家使用。下面這篇文章主要給大家介紹了關(guān)于PHP性能分析工具xhprof的安裝與使用方法的相關(guān)資料,需要的朋友可以參考下。2017-12-12
PHP5中虛函數(shù)的實(shí)現(xiàn)方法分享
學(xué)過C++的人都應(yīng)該知道C++中有個虛函數(shù)的概念。而在php5中如何實(shí)現(xiàn)這個虛函數(shù)呢?2011-04-04

