当前位置:首页 » 编程语言 » php过滤特殊字符

php过滤特殊字符

发布时间: 2022-06-29 23:22:44

php 如何过滤特殊字符,如 ◆ )- : 、 、!! /   等

可以用 str_replace() 函数统一替换,如:
$string = "测试◆例子♂ 在此 !";
$replace = array('◆','♂',')','=','+','$','¥','-','、','、',':',';','!','!','/');
$string = str_replace($replace, '', $string);
echo $string;

Ⅱ php怎样过滤非法字符防止sql注入

htmlspecialchars($_POST['字段']),用这个函数就可以将一些特殊字符进行过滤转义。你可以去看看这个函数的说明。

Ⅲ PHP 如何过滤特殊字符 如 ◆ )- : 、 、!! / 等

PHP 中的 preg_replace() 函数可以实现

实例:只匹配中文


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

Ⅳ php 如何过滤特殊字符 如图这是编辑器中的内容放在记事本文件中出现的,小黑格就是特殊字符

小黑点应该是换行符吧!
其实可以用
<?php
$string = "换行测试".chr(13).chr(10)."第二行测试";
$fp = fopen('a.txt','w+');
fwrite($fp,$string);
fclose($fp);
?>

Ⅳ PHP 如何过滤特殊字符 如◆

可以用 str_replace() 函数统一替换,如:
$string = "测试◆例子♂ 在此 !";
$replace = array('◆','♂',')','=','+','$','¥','-','、','、',':',';','!','!','/');
$string = str_replace($replace, '', $string);
echo $string;

Ⅵ PHP怎样过滤中文状态下特殊字符(比如标点符号)

123456789101112131415function filterGBK_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='广~·@#¥%……&*()——+|-=、{}【】:;“”‘’~“《》,。?、州;?海【,鲜。餐“”】(,厅) ';echo filterGBK_SpecialChars($str);

Ⅶ php 如何过滤 单引号 双引号 $ < > 等N种特殊符号谢谢

我给楼主吧- - 首先是过滤html,将html编码转换为实体编码 /**
* 将特殊字符转成 HTML 格式。
* @param string $value - 字符串或者数组
* @return array
*/
public static function htmlspecialchars($value) {
return is_array($value) ? array_map('k::htmlspecialchars', $value) :
preg_replace('/&((#(\d{3,5}|x[a-fA-F0-9]{4})|[a-zA-Z][a-z0-9]{2,5});)/', '&\\1',
str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), $value));
} 还有一个去除html编码的,可以直接用php的函数strip_tags()

Ⅷ PHP如何过滤★等特殊符号

我的程序是这样编写的,相信你一看就懂:

if(preg_match("/[ '.,:;*?~`!@#$%^&+=)(<>{}]|\]|\[|\/|\\\|\"|\|/",$user)){
echo '不要在名字里面整些特殊符号,请只使用字母、数字和汉字,当然要你的浏览器要选简体中文GB2312哟,千万不要选繁体、中文HZ等。返回修改后,再来,我等你哟!';
exit();
}

Ⅸ PHP字符串中特殊符号的过滤方法介绍

本篇文章主要是对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);

return
trim($str);
}

Ⅹ php 过滤特殊字符,但不能过滤掉下划线,点,减号

特殊符号太多了,可以反向来写.
下划线,点,减号都能匹配,还有想要的都匹配就行了.
改变一下思维方式就了,如果可以帮到你,希望采纳.

热点内容
如何获得打印机无线密码 发布:2024-05-04 06:44:59 浏览:416
上古诸神录哪里改密码 发布:2024-05-04 06:43:55 浏览:261
灌篮高手手游自动盖帽脚本 发布:2024-05-04 06:42:31 浏览:423
javajs引擎 发布:2024-05-04 06:37:33 浏览:796
javalist重复 发布:2024-05-04 06:19:27 浏览:509
max脚本管理 发布:2024-05-04 06:02:31 浏览:45
自行搭建服务器 发布:2024-05-04 06:01:12 浏览:125
h3c如何查看所有配置 发布:2024-05-04 05:26:39 浏览:493
java统计字符串中字母个数 发布:2024-05-04 05:22:58 浏览:888
throwablejava 发布:2024-05-04 05:22:56 浏览:792