导航:首页 > 编程语言 > php过滤特殊符号

php过滤特殊符号

发布时间:2022-05-09 20:22:17

php如何过滤★等特殊符号

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

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

Ⅱ 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字符串中特殊符号的过滤方法进行了详细的介绍,需要的朋友可以过来参考下,希望对大家有所帮助
有时候我们会遇到过滤字符串中特殊字符的问题,本文提供了一个处理特殊字符串的方法,可能有遗漏,如果读者发现了可以
代码如下:
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 如何过滤特殊字符 如 ◆ )- : 、 、!! / 等

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

实例:只匹配中文


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

Ⅳ php 正则过滤特殊符号◆●★

如果 就是这3个的话 没必要用正则
直接写死了 过滤就行

如果不光这3个,那就得 搞清楚这些字符的范围
每个中文字符都有个编码 0x000000 这个样子的

0x000000 ~~0x000111 比如这些范围代表这堆符号 就写这个范围替换就行了

Ⅵ php数组内元素去除特殊符号

首先你的数组必须是字符串数组,如果不是你要用strval()函数把每一个数组元素转换成字符串,

然后,用preg_replace函数把'-'替换成空字符串,就行了。

完整的php程序如下:

<?php

$arr=array('2015-01','2015-02','2015-03','2015-04');

for($i=0;$i<count($arr);$i++){

$arr[$i]=preg_replace('#-#','',$arr[$i]);

}

print_r($arr);

?>

运行结果:

Array ( [0] => 201501 [1] => 201502 [2] => 201503 [3] => 201504 )

Ⅶ php过滤指定字符的函数

explode — 使用一个字符串分割另一个字符串

array explode ( string $delimiter , string $string [, int $limit ] )

此函数返回由字符串组成的数组,每个元素都是 string 的一个子串,它们被字符串 delimiter 作为边界点分割出来。

<?php
//示例1
$pizza="";
$pieces=explode("",$pizza);
echo$pieces[0];//piece1
echo$pieces[1];//piece2

//示例2
$data="foo:*:1023:1000::/home/foo:/bin/sh";
list($user,$pass,$uid,$gid,$gecos,$home,$shell)=explode(":",$data);
echo$user;//foo
echo$pass;//*

?>

Ⅷ php 如何过滤掉xml中的特殊字符

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

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

//xmlencoding
if(!isset($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过滤特殊符号相关的资料

热点内容
海南高德司机端是什么app 浏览:861
pid命令 浏览:886
一天一图学会python可视化 浏览:307
魔兽编辑文本命令串 浏览:495
android中view绘制 浏览:796
安卓机内存删除怎么恢复 浏览:329
Qt环境的编译软件放到linux 浏览:212
联创打印系统怎么连接服务器 浏览:935
杭州行政命令 浏览:160
如何查找服务器日志 浏览:801
加密的钥匙扣怎么写 浏览:579
文件夹更新不了怎么办 浏览:475
压缩机指示灯亮是什么原因 浏览:956
什么app订酒店半价 浏览:765
中老年解压神器 浏览:243
讯飞语音ttsandroid 浏览:468
腰椎压缩性骨折术后能坐车吗 浏览:507
python类装饰器参数 浏览:349
均线pdf微盘 浏览:792
女生喜欢玩的解压游戏 浏览:442