$_SERVER['QUERY_STRING'] does not print unicode values as it is

前端 未结 2 1560
故里飘歌
故里飘歌 2021-01-26 08:07

http://localhost/fw/api/fw_api.php?rule=unicode&action=create&phrase=යුනිකෝඩ්

I accessing the above url. In fw_api.php, when I echo the

相关标签:
2条回答
  • 2021-01-26 08:46
    1. Encode a value with special characters.

      $token = "a{l@3a3s9a";
      rawurlencode($token);   //The coding would be "%7Bl%403a3s9a"
      
    2. Send the encoded value to the database

    3. Receive the parameter value by URL

      $body = file_get_contents("php://input");
      if ($body == null && isset($_SERVER['QUERY_STRING'])) {
          parse_str($_SERVER['QUERY_STRING'], $this->parameters);
          return;
      }
      

      The parameter values are automatically decoded with parse_str () without the need to use rawurldecode()

    4. Use the value obtained by URL ("a{l@3a3s9a")

    This encoding would be used to obtain special characters through a URL segment.

    GL

    0 讨论(0)
  • 2021-01-26 09:01

    The actual value is actually "%E0%B6%BA%E0%B7%94%E0..."!

    URLs must consist of a subset of ASCII, they cannot contain other "Unicode characters". Your browser may be so nice as to let you input arbitrary Unicode characters and actually display them as characters, but behind the scenes the URL value is percent encoded. You'll have to decode it with rawurldecode.

    The query string is automatically being parsed and decoded by PHP and placed in the $_GET array (and $_POST for the request body). But the raw query string you'll have to parse and decode yourself.

    0 讨论(0)
提交回复
热议问题