PHP 过滤特殊字符和HTML字符对照表

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
<title>PHP字符串的过滤方法</title>
</head>
<body>
<?php
function strFilter($str){
	//过滤HTML的标记和分号
	$str = str_replace('\'', '&#39;', $str);
	$str = str_replace('\'', '&#39;', $str);
	$str = str_replace('\\', '', $str);   		
	$str = str_replace('"', '&#34;', $str);
	$str = str_replace('<', '&#60;', $str);
	$str = str_replace('>', '&#62;', $str);
	return trim($str);
}
$cont = '   ?”?;onestopweb.cn  and update //\  as  chaoyi 》、   ';
echo '开始['.strFilter($cont).']结束';
?>
</body>
</html>
 
效果图:
提示:过滤特殊字符是很关键的,它一定程度上能防止SQL注入。所以为了自己的网站安全,在前端的JS做过滤,也在后端的编程也做过滤。下面提供的是如何解决HTML的特殊符号:
 
HTML 特殊符号编码对照表
特殊符号命名实体十进制编码特殊符号命名实体十进制编码特殊符号命名实体十进制编码
Α&Alpha;&#913;Β&Beta;&#914;Γ&Gamma;&#915;
Δ&Delta;&#916;Ε&Epsilon;&#917;Ζ&Zeta;&#918;
Η&Eta;&#919;Θ&Theta;&#920;Ι&Iota;&#921;
Κ&Kappa;&#922;Λ&Lambda;&#923;Μ&Mu;&#924;
Ν&Nu;&#925;Ξ&Xi;&#926;Ο&Omicron;&#927;
Π&Pi;&#928;Ρ&Rho;&#929;Σ&Sigma;&#931;
Τ&Tau;&#932;Υ&Upsilon;&#933;Φ&Phi;&#934;
Χ&Chi;&#935;Ψ&Psi;&#936;Ω&Omega;&#937;
α&alpha;&#945;β&beta;&#946;γ&gamma;&#947;
δ&delta;&#948;ε&epsilon;&#949;ζ&zeta;&#950;
η&eta;&#951;θ&theta;&#952;ι&iota;&#953;
κ&kappa;&#954;λ&lambda;&#955;μ&mu;&#956;
ν&nu;&#957;ξ&xi;&#958;ο&omicron;&#959;
π&pi;&#960;ρ&rho;&#961;ς&sigmaf;&#962;
σ&sigma;&#963;τ&tau;&#964;υ&upsilon;&#965;
φ&phi;&#966;χ&chi;&#967;ψ&psi;&#968;
ω&omega;&#969;ϑ&thetasym;&#977;ϒ&upsih;&#978;
ϖ&piv;&#982;&bull;&#8226;&hellip;&#8230;
&prime;&#8242;&Prime;&#8243;&oline;&#8254;
&frasl;&#8260;&weierp;&#8472;&image;&#8465;
&real;&#8476;&trade;&#8482;&alefsym;&#8501;
&larr;&#8592;&uarr;&#8593;&rarr;&#8594;
&darr;&#8595;&harr;&#8596;&crarr;&#8629;
&lArr;&#8656;&uArr;&#8657;&rArr;&#8658;
&dArr;&#8659;&hArr;&#8660;&forall;&#8704;
&part;&#8706;&exist;&#8707;&empty;&#8709;
&nabla;&#8711;&isin;&#8712;&notin;&#8713;
&ni;&#8715;&prod;&#8719;&sum;&#8722;
&minus;&#8722;&lowast;&#8727;&radic;&#8730;
&prop;&#8733;&infin;&#8734;&ang;&#8736;
&and;&#8869;&or;&#8870;&cap;&#8745;
&cup;&#8746;&int;&#8747;&there4;&#8756;
&sim;&#8764;&cong;&#8773;&asymp;&#8773;
&ne;&#8800;&equiv;&#8801;&le;&#8804;
&ge;&#8805;&sub;&#8834;&sup;&#8835;
&nsub;&#8836;&sube;&#8838;&supe;&#8839;
&oplus;&#8853;&otimes;&#8855;&perp;&#8869;
&sdot;&#8901;&lceil;&#8968;&rceil;&#8969;
&lfloor;&#8970;&rfloor;&#8971;&loz;&#9674;
&spades;&#9824;&clubs;&#9827;&hearts;&#9829;
&diams;&#9830;
 
&nbsp;&#160;¡&iexcl;&#161;
¢&cent;&#162;£&pound;&#163;¤&curren;&#164;
¥&yen;&#165;¦&brvbar;&#166;§&sect;&#167;
¨&uml;&#168;©&copy;&#169;ª&ordf;&#170;
«&laquo;&#171;¬&not;&#172;
 
&shy;&#173;
®&reg;&#174;¯&macr;&#175;°&deg;&#176;
±&plusmn;&#177;²&sup2;&#178;³&sup3;&#179;
´&acute;&#180;µ&micro;&#181"&quot;&#34;
<&lt;&#60;>&gt;&#62;'
 
&#39;

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值