PHP uses get to obtain garbled characters in the url. geturl
This example describes how PHP uses get to obtain garbled characters in URLs. Share it with you for your reference. The specific method is as follows:
I. Problems:
I was going to use it like this.
Copy codeThe Code is as follows: <a href = "list. php? Plate = jurisdiction Dynamics "charset =" UTF-8 "target =" main "> [view jurisdiction dynamics] </a>
The result is displayed on the list. php page: view [dynamic region of the jurisdiction].
At first, I guess the encoding of the Chinese character "state" is in conflict with some things, so garbled characters may occur.
Ii. solution:
Usage:
Copy codeThe Code is as follows: <a href = "list. php? Plate = <? Php echo urlencode ("region Dynamics");?> "Charset =" UTF-8 "target =" main "> [view] </a>
Use the following code on the list. php page:
Copy codeThe Code is as follows:
<? Php
Header ("Content-type: text/html; charset = UTF-8 ");
If ($ _ GET ['plate '])
Echo $ plate = urldecode ($ _ GET ['plate ']);
?>
It won't be garbled and the transmission is not normal.
Note that the encoding of the received GET page must be the same as that of the sender!
About the string urlencode (string $ str) Function
This function allows you to encode a string and use it in the URL request section. It also allows you to pass variables to the next page.
Example 1 urlencode ()
Copy codeThe Code is as follows: <? Php
Echo '<a href = "mycgi? Foo = ', urlencode ($ userinput),' "> ';
?>
Example 2 urlencode () and htmlentities ()
Copy codeThe Code is as follows: <? Php
$ Query_string = 'foo = '. urlencode ($ foo).' & bar = '. urlencode ($ bar );
Echo '<a href = "mycgi? '. Htmlentities ($ query_string).' "> ';
?>
I hope this article will help you with PHP programming.