當前位置:首頁 » 凈水方式 » php過濾特殊字元

php過濾特殊字元

發布時間: 2020-12-15 20:12:27

Ⅰ php中如何過濾所有的特殊字元

  1. 用正則匹配替換

  2. 用函數str_replace一個一個替換

Ⅱ mysql如何過濾特殊字元用PHP語言。高分求助,給補分

function deletehtml($str) {
$str = trim($str);
$str = preg_replace("</P>","1234a3211",$str);
$str = preg_replace("</p>","1234a3211",$str);
$str = preg_replace("<br/>","1234a3211",$str);

$str = preg_replace("/<(.[^>]*)>/","",$str);
$str = preg_replace("/([\r\n])[\s]+/","",$str);
$str = preg_replace("/-->/","",$str);
$str = preg_replace("/<!--.*/","",$str);
$str = preg_replace("/&(quot|#34);/","",$str);

$str = preg_replace("/&(amp|#38);/", "/&/",$str);
$str = preg_replace("/&(lt|#60);/", "/</",$str);
$str = preg_replace("/&(gt|#62);/", ">",$str);
$str = preg_replace("/&(nbsp|#160);/", "",$str);
$str = preg_replace("/&(iexcl|#161);/", "/\xa1/",$str);
$str = preg_replace("/&(cent|#162);/", "/\xa2/",$str);
$str = preg_replace("/&(pound|#163);/", "/\xa3/",$str);
$str = preg_replace("/&(|#169);/", "/\xa9/",$str);
$str = preg_replace("/&#(\d+);/", "",$str);

$str = preg_replace("/</", "",$str);
$str = preg_replace("/>/", "",$str);
$str = preg_replace("/\r\n/", "",$str);
$str = preg_replace("/1234a3211/", "/<br/>/",$str);

return $str;
}

Ⅲ php 過濾特殊字元,但不能過濾掉下劃線,點,減號

特殊符號太多了,可以反向來寫.
下劃線,點,減號都能匹配,還有想要的都匹配就行了.
改變一下思維方式就了,如果可以幫到你,希望採納.

Ⅳ PHP怎樣過濾中文狀態下特殊字元(比如標點符號)

functionfilterGBK_SpecialChars($str)
{
$str=urlencode($str);//將關鍵字編碼
//下面的必須寫在一行,不可換行截斷
$str=preg_replace("/(%7E|%60|%21|%40|%23|%24|%25|%5E|%26|%27|
%2A|%28|%29|%2B|%7C|%5C|%3D|-|_|%5B|%5D|%7D|%7B|%3B|%22|%3A|
%3F|%3E|%3C|%2C|.|%2F|%A3%BF|%A1%B7|%A1%B6|%A1%A2|%A1%A3|%A3%AC|
%7D|%A1%B0|%A3%BA|%A3%BB|%A1%AE|%A1%AF|%A1%B1|%A3%FC|%A3%BD|%A1%AA|
%A3%A9|%A3%A8|%A1%AD|%A3%A4|%A1%A4|%A3%A1|%A1%AB|%A3%FB|%A3%FD|%A1%BE|
%A1%BF|)+/",'',$str);
$str=urldecode($str);//將過濾後的關鍵字解碼
return$str;
}
$str='廣~·@#¥%……&*()——+|-=、{}【】:;「」『』~「《》,。?、州;?海【,鮮。餐「」】(,廳)';
echofilterGBK_SpecialChars($str);

Ⅳ PHP 如何過濾特殊字元 如 ◆ )- : 、 、!! / 等

^

PHP 中的 preg_replace() 函數可以實現

實例:只匹配中文


<?php
$str="php)!內!編程";
echopreg_replace("/[^容x{4e00}-x{9fa5}]/iu",'',$str);
?>

Ⅵ php中執行sql時,裡麵包含的特殊字元被莫名奇妙的截斷了

mysql_escape_string()把欄位用這個函數轉一下。。。

Ⅶ php 如何過濾特殊字元,如 ◆ )- : 、 、!! /   等

可以用 str_replace() 函數統一替換,如:
$string = "測試◆例子♂回 在此 !";
$replace = array('◆','♂',')','=','+','$','¥','-','、答','、',':',';','!','!','/');
$string = str_replace($replace, '', $string);
echo $string;

Ⅷ php 如何過濾特殊字元 如圖這是編輯器中的內容放在記事本文件中出現的,小黑格就是特殊字元

小黑點應該是換行符吧!
其實可以用
<?php
$string = "換行測試版".chr(13).chr(10)."第二權行測試";
$fp = fopen('a.txt','w+');
fwrite($fp,$string);
fclose($fp);
?>

Ⅸ php 如何過濾掉xml中的特殊字元

|

functionxmlentities($string,$quote_style=ENT_QUOTES)
{
static$trans;

//
//
$string=html_entity_decode($string,ENT_QUOTES);

//xmlencoding
if(!($trans))
{
$trans=get_html_translation_table(HTML_ENTITIES,$quote_style);
foreach(array_keys($trans)as$key)
{
$trans[$key]='&#'.ord($key).';';
}
//donttranslatethe'&'incaseitispartof&xxx;
$trans[chr(38)]='&';
}

//aftertheinitialtranslation,_do_mapstandalone'&'into'&#38;'
$str_temp=preg_replace("/&(?![A-Za-z]{0,4}w{2,3};|#[0-9]{2,3};)/u"
,"&#38;"
,strtr($string,$trans)
);
return$str_temp;
}

Ⅹ PHP 如何過濾特殊字元 如◆

可以用復 str_replace() 函數統一制替換,如:
$string = "測試◆例子♂ 在此 !";
$replace = array('◆','♂',')','=','+','$','¥','-','、','、',':',';','!','!','/');
$string = str_replace($replace, '', $string);
echo $string;

熱點內容
丁度巴拉斯情人電影推薦 發布:2024-08-19 09:13:07 瀏覽:886
類似深水的露點電影 發布:2024-08-19 09:10:12 瀏覽:80
《消失的眼角膜》2電影 發布:2024-08-19 08:34:43 瀏覽:878
私人影院什麼電影好看 發布:2024-08-19 08:33:32 瀏覽:593
干 B 發布:2024-08-19 08:30:21 瀏覽:910
夜晚看片網站 發布:2024-08-19 08:20:59 瀏覽:440
台灣男同電影《越界》 發布:2024-08-19 08:04:35 瀏覽:290
看電影選座位追女孩 發布:2024-08-19 07:54:42 瀏覽:975
日本a級愛情 發布:2024-08-19 07:30:38 瀏覽:832
生活中的瑪麗類似電影 發布:2024-08-19 07:26:46 瀏覽:239