这篇文章主要介绍了PHP实现Javascript中的escape及unescape函数代码分享,本文给出两个实现版本,需要的朋友可以参考下
这个类相当好用.作用么,PHP做JSON传递GBK字符,比如中文,日文,韩文神马的Unicode最合适不过了..
1){// 多字节字符 $return.='%u'.strtoupper(bin2hex(mb_convert_encoding($str,'UCS-2',$encoding))); }else{ $return.='%'.strtoupper(bin2hex($str)); } } return$return; } functiongb2utf8($string,$encoding='utf-8',$from_encode='gb2312') { returnmb_convert_encoding($string,$encoding,$from_encode); } } ?>
google code 上找到的另外一个类似脚本
=127) { $tmpString=bin2hex(iconv("gbk","ucs-2",substr($str,$i,2))); $tmpString=substr($tmpString,2,2).substr($tmpString,0,2); $retrunString.="%u".$tmpString; $i++; }else{ $retrunString.="%".dechex(ord($str[$i])); } } return$retrunString; } functionescape($str) { preg_match_all("/[\x80-\xff].|[\x01-\x7f]+/",$str,$r); $ar=$r[0]; foreach($aras$k=>$v) { if(ord($v[0])$v) { if(substr($v,0,2)=="%u") $ar[$k]=iconv("UCS-2","UTF-8",pack("H4",substr($v,-4))); elseif(substr($v,0,3)=="") $ar[$k]=iconv("UCS-2","UTF-8",pack("H4",substr($v,3,-1))); elseif(substr($v,0,2)=="") { //echo substr($v,2,-1).""; $ar[$k]=iconv("UCS-2","UTF-8",pack("n",substr($v,2,-1))); } } returnjoin("",$ar); } ?>
,
Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download
The most popular open source editor

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 English version
Recommended: Win version, supports code prompts!
