Two ways to pass a Chinese parameter to a PHP page through JS ____php

Source: Internet
Author: User
Tags pack

On the Internet to find, first stay, for later use, see comments that this is for UTF-8 coding


Found two of the most common methods for the time being.
////////////////////////////////////
The first kind of direct URL coding is more convenient
Js:
[JavaScript] view plain copy <script type= "Text/javascript" > String = encodeURIComponent (string);   Location.href = Index.php?keyword= ' +string; </script> ————————————————
Php:
[PHP] view plain copy $keyword = (isset ($_get[' keyword '))?   $_get[' keyword ']: "; //////////////////////////////////////////////////////////////////
The second use of escape coding is more complex but concurrent sex seems to be better, passing through Ajax may need
Js:
[JavaScript] view Plain copy ... $.getjson ("admin.php?action=" +escape (Action), function (JSON) {}) ...

Php:
[PHP] view plain copy function unescape ($STR) {//define unescape function $str = UrlDecode ($STR); Preg_match_all ("/(?:%u.{4}|& #x.; |   & #d +;|.+)/U ", $str, $r);   $ar = $r [0];   foreach ($ar as $k => $v) {if (substr ($v, 0,2) = = "%u") $ar [$k] = Iconv ("Ucs-2be", "Utf-8″,pack (" H4″,substr ($v,-4)));   ElseIf (substr ($v, 0,3) = = "& #x") $ar [$k] = Iconv ("Ucs-2be", "Utf-8″,pack (" H4″,substr ($v, 3,-1)));   ElseIf (substr ($v, 0,2) = = "&#") {$ar [$k] = Iconv ("Ucs-2be", "Utf-8″,pack (" n ", substr ($v, 2,-1)));   } return Join ("", $ar); } $action =unescape ($_get["action"));

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.