php中escape unescape的写法
发布:smiling 来源: PHP粉丝网 添加日期:2014-08-25 09:15:25 浏览: 评论:0
- */
- function phpescape($str){
- $sublen=strlen($str);
- $restring="";
- for ($i=0;$i<$sublen;$i++){
- if(ord($str[$i])>=127){
- $tmps教程tring=bin2hex(iconv("utf-8","ucs-2",substr($str,$i,2)));
- if (!eregi("win",php_os)){
- $tmpstring=substr($tmpstring,2,2).substr($tmpstring,0,2);
- }
- $restring.="%u".$tmpstring;
- $i++;
- } else {
- $restring.="%".dechex(ord($str[$i]));
- }
- }
- return $restring;
- }
- function unescape($str) {
- $str = rawurldecode($str);
- preg_match_all("/%u.{4}|&#x.{4};|&#d+;|.+/u",$str,$r);
- $ar = $r[0];
- foreach($ar as $k=>$v) {
- if(substr($v,0,2) == "%u")
- $ar[$k] = iconv("ucs-2","utf-8",pack("h4",substr($v,-4)));
- elseif(substr($v,0,3) == "&#x")
- $ar[$k] = iconv("ucs-2","utf-8",pack("h4",substr($v,3,-1)));
- elseif(substr($v,0,2) == "&#") {
- $ar[$k] = iconv("ucs-2","utf-8",pack("n",substr($v,2,-1)));
- }
- }
- return join("",$ar);
- }
- function escape($str) {
- preg_match_all("/[x80-xff].|[x01-x7f]+/",$str,$r);
- $ar = $r[0];
- foreach($ar as $k=>$v) {
- if(ord($v[0]) < 128)
- $ar[$k] = rawurlencode($v);
- else
- $ar[$k] = "%u".bin2hex(iconv("gb2312","ucs-2",$v));
- }
- return join("",$ar);
- }
- function unescape($str) {
- $str = rawurldecode($str);
- preg_match_all("/(?:%u.{4})|.+/",$str,$r);
- $ar = $r[0];
- foreach($ar as $k=>$v) {
- if(substr($v,0,2) == "%u" && strlen($v) == 6)
- $ar[$k] = iconv("ucs-2","gb2312",pack("h4",substr($v,-4)));
- } //开源代码phpfensi.com
- return join("",$ar);
- }
Tags: escape unescape php写法
相关文章
- ·javascript unescape() escape() 字符编码解码函数(2013-11-28)
- ·js的escape转义中文php的转换函数(2013-12-27)
- ·php mysql_real_escape_string()函数(2014-09-11)
- ·mysql_real_escape_string(2014-09-12)
- ·PHP中addslashes与mysql_escape_string的区别分析(2019-08-18)
- ·mysql_escape_string()函数用法分析(2019-08-22)
- ·PHP函数addslashes和mysql_real_escape_string的区别(2020-11-19)
- ·PHP实现Javascript中的escape及unescape函数代码分享(2021-05-11)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)