当前位置:首页 » 编程语言 » php过滤非中文

php过滤非中文

发布时间: 2025-09-17 00:02:13

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

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

Ⅱ php怎么过滤特殊汉字

可以用一个文本或者一个表把特殊汉字按照一定规则存储好,每次请求过来用strpos做过滤就好了,这种方式根据特殊汉字的多少而直接影响响应速度与访问时长,不建议数据源过大。如果是数据源过大的话,可以考虑mysql的全文索引机制。如果是过滤所有汉字,就用ascii码对照

Ⅲ 用php过滤html部分标签

$str=preg_replace("/\s+/", " ", $str); //过滤多余回车
$str=preg_replace("/<[ ]+/si","<",$str); //过滤<__("<"号后面带空格)

$str=preg_replace("/<\!--.*?-->/si","",$str); //注释
$str=preg_replace("/<(\!.*?)>/si","",$str); //过滤DOCTYPE
$str=preg_replace("/<(\/?html.*?)>/si","",$str); //过滤html标签
$str=preg_replace("/<(\/?head.*?)>/si","",$str); //过滤head标签
$str=preg_replace("/<(\/?meta.*?)>/si","",$str); //过滤meta标签
$str=preg_replace("/<(\/?body.*?)>/si","",$str); //过滤body标签
$str=preg_replace("/<(\/?link.*?)>/si","",$str); //过滤link标签
$str=preg_replace("/<(\/?form.*?)>/si","",$str); //过滤form标签
$str=preg_replace("/cookie/si","COOKIE",$str); //过滤COOKIE标签

$str=preg_replace("/<(applet.*?)>(.*?)<(\/applet.*?)>/si","",$str); //过滤applet标签
$str=preg_replace("/<(\/?applet.*?)>/si","",$str); //过滤applet标签

$str=preg_replace("/<(style.*?)>(.*?)<(\/style.*?)>/si","",$str); //过滤style标签
$str=preg_replace("/<(\/?style.*?)>/si","",$str); //过滤style标签

$str=preg_replace("/<(title.*?)>(.*?)<(\/title.*?)>/si","",$str); //过滤title标签
$str=preg_replace("/<(\/?title.*?)>/si","",$str); //过滤title标签

$str=preg_replace("/<(object.*?)>(.*?)<(\/object.*?)>/si","",$str); //过滤object标签
$str=preg_replace("/<(\/?objec.*?)>/si","",$str); //过滤object标签

$str=preg_replace("/<(noframes.*?)>(.*?)<(\/noframes.*?)>/si","",$str); //过滤noframes标签
$str=preg_replace("/<(\/?noframes.*?)>/si","",$str); //过滤noframes标签

$str=preg_replace("/<(i?frame.*?)>(.*?)<(\/i?frame.*?)>/si","",$str); //过滤frame标签
$str=preg_replace("/<(\/?i?frame.*?)>/si","",$str); //过滤frame标签

$str=preg_replace("/<(script.*?)>(.*?)<(\/script.*?)>/si","",$str); //过滤script标签
$str=preg_replace("/<(\/?script.*?)>/si","",$str); //过滤script标签
$str=preg_replace("/javascript/si","Javascript",$str); //过滤script标签
$str=preg_replace("/vbscript/si","Vbscript",$str); //过滤script标签
$str=preg_replace("/on([a-z]+)\s*=/si","On\\1=",$str); //过滤script标签
$str=preg_replace("/&#/si","&#",$str); //过滤script标签,如javAsCript:alert(

清除空格,换行

function DeleteHtml($str)
{
$str = trim($str);
$str = strip_tags($str,"");
$str = ereg_replace("\t","",$str);
$str = ereg_replace("\r\n","",$str);
$str = ereg_replace("\r","",$str);
$str = ereg_replace("\n","",$str);
$str = ereg_replace(" "," ",$str);
return trim($str);
}

过滤HTML属性

1,过滤所有html标签的正则表达式:

复制代码 代码如下:

</?[^>]+>

//过滤所有html标签的属性的正则表达式:

$html = preg_replace("/<([a-zA-Z]+)[^>]*>/","<\\1>",$html);

3,过滤部分html标签的正则表达式的排除式(比如排除<p>,即不过滤<p>):

复制代码 代码如下:

</?[^pP/>]+>

4,过滤部分html标签的正则表达式的枚举式(比如需要过滤<a><p><b>等):

复制代码 代码如下:

</?[aApPbB][^>]*>

5,过滤部分html标签的属性的正则表达式的排除式(比如排除alt属性,即不过滤alt属性):

复制代码 代码如下:

\s(?!alt)[a-zA-Z]+=[^\s]*

6,过滤部分html标签的属性的正则表达式的枚举式(比如alt属性):

复制代码 代码如下:

(\s)alt=[^\s]*

热点内容
c语言怎么安装 发布:2025-09-17 01:43:30 浏览:791
android控件设置位置设置 发布:2025-09-17 01:36:17 浏览:447
mfc与c语言 发布:2025-09-17 01:33:52 浏览:31
扣扣空间相册怎么加密 发布:2025-09-17 01:32:21 浏览:872
移动文件夹的软件 发布:2025-09-17 01:31:47 浏览:646
联通吉林省dns服务器地址 发布:2025-09-17 01:26:56 浏览:960
python列表删除指定元素 发布:2025-09-17 01:26:13 浏览:942
安卓手机设置安全管理器有什么用 发布:2025-09-17 01:23:32 浏览:900
mysql数据库备份的方法 发布:2025-09-17 01:22:55 浏览:572
c语言中函数返回值的类型是由 发布:2025-09-17 01:21:16 浏览:887