php过滤特殊字符
Ⅰ php中如何过滤所有的特殊字符
用正则匹配替换
用函数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'&'
$str_temp=preg_replace("/&(?![A-Za-z]{0,4}w{2,3};|#[0-9]{2,3};)/u"
,"&"
,strtr($string,$trans)
);
return$str_temp;
}
Ⅹ PHP 如何过滤特殊字符 如◆
可以用复 str_replace() 函数统一制替换,如:
$string = "测试◆例子♂ 在此 !";
$replace = array('◆','♂',')','=','+','$','¥','-','、','、',':',';','!','!','/');
$string = str_replace($replace, '', $string);
echo $string;