This article describes the PHP implementation of JS Escape and unescape method. Share to everyone for your reference, specific as follows:
Escape and unescape in JavaScript is it? The string is converted to Unicode hexadecimal encoding, the same as the JSON encoding format, so you can pass the Json_encode and Json_ in PHP Decode implements the PHP version of Escape and unescape.
The code is as follows:
<?php
function Escape ($str) {return
str_replace (' \ \ ', '% ', substr (Json_encode ($STR), 1,-1));
}
function Unescape ($str) {return
Json_decode (' "'. Str_replace ('% ', ' \ \ ', $str). ')
$str = '%u5f90%u5dde%u5e02%u811a%u672c%u4e4b%u5bb6 1234 ';
$str _escape = ' XUZHOU cloud Habitat Community 1234 ';
echo "$str <br>\n$str_escape<br>\n";
echo unescape ($STR), "<br>\n";
Echo Escape ($str _escape), "<br>\n";
The results of the operation are as follows:
%U5F90%U5DDE%U5E02%U811A%U672C%U4E4B%U5BB6 1234
Xuzhou cloud-dwelling community 1234 Xuzhou
cloud-Habitat Community 1234%U5F90%U5DDE%U5E02%u811a
%U672C%U4E4B%U5BB6 1234
More interested in PHP related content readers can view the site topics: "PHP JSON format data Operation tips Summary", "PHP error and Exception handling method summary", "PHP string (String) Usage summary", "PHP Array" Operation Techniques Encyclopedia, " Summary of PHP operation and operator usage, "Summary of PHP Network programming skills", "Introduction to PHP Basic Grammar", "PHP Introduction to Object-oriented Programming", "Php+mysql Database Operation Introduction" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design.