Ⅰ php过滤上传类型,只上传图片类型文件
你可以这样,如果说你的上传文件文件名是$uploadfilename,那么可以用
$str = end(explode(".",$uploadfilename));获得上传文件的扩展名,专然后再进行判属断if($str=="jpg" or $str=="jpeg" or $str=="gif" or $str=="png")的时候才执行上传,否则返回错误提示信息,这样子来限制上传文件类型
Ⅱ php 如何过滤用户提交的javascript代码
进行html标签转义,例如传入内容是$content=“<script>alert('sd');</script>”,运行
$content=htmlspecialchars($content);就会将你的内容转换成
(这回个是转换后插进数据库里的答数据)
这个东西放在浏览器显示就是
<script>alert('sd');</script>,但是不会运行里面的函数。
Ⅲ 用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]*
Ⅳ php多条件查询问题,怎么过滤空值
是的正如你所说有两种解决方案,第一种是采用PHP的方式,先判断数据的合法性,比如是否提交了空值(推荐使用,没有垃圾数据);第二种不做任何判断,空值也能提交到数据库,只是在SQL查询时过滤空值数据(不推荐使用,有垃圾数据)。
解决方案1(通过PHP过滤空值数据):
if($_POST['字段']=='')exit('<scripttype="text/javascript">alert("数据不合法!");history.back();</script>');//依此类推,逐一判断表单$_POST数据
解决方案2(通过SQL查询来过滤空值数据):
SELECT`字段名`FROM`表名`WHERE`字段1`NOTIN('',NULL)AND`字段2`NOTIN('',NULL)...;
以上就是两种解决方案,我推荐两种方案组合使用,这样确保万无一失,如有问题欢迎追问~
Ⅳ PHP if ($_GET['key'] 过滤
如果是特殊的需要key匹配的特点去写正则匹配.例如
$w='kjhgerz123z1iuhiugerhhg';
$s='kjhgerz2z1iuhiugerhhg';
$m='/z[0-9]{2,}/';
if(preg_match($m,$w)){
echo"出现关键字";
}else{
echo"关键字未出现过";
}
if(preg_match($m,$s)){
echo"出现关键字";
}else{
echo"关键字未出现过";
}
Ⅵ 分别在Javascript和php下过滤+-=._/外
var reg=/^[\w\+\-\=\.\/]+$/;
var str="123";
alert(reg.test(str));
这个正则应该可以了。
经过javascript的简单测试。
Ⅶ php怎样过滤span标签之后的所有内容
$str="111<span>asdfsadfsafsd</span>";
//$str=preg_replace("/<(span.*?)>(.*?)<(\/span.*?)>/si","",$str); //过滤<span>及其中内间的内容容
$str=preg_replace("/<span>(.*?)<span>/si","",$str); //只过滤<span>中间的内容不过滤<span>
echo $str;
Ⅷ php怎样过滤非法字符防止sql注入
htmlspecialchars($_POST['字段']),用这个函数就可以将一些特殊字符进行过滤转义。你可以去看看这个函数的说明。