The example of this article is about the solution of using get to obtain URL character garbled in PHP. Share to everyone for your reference. The specific methods are as follows:
First, the question:
I was going to use this.
Copy Code code as follows:
<a href= "list.php?plate= area dynamic" charset= "Utf-8" target= "main" >[View District Dynamics]</a>
Results on the list.php page is-– view [jurisdiction move Yiwen]
The first guess may be that the "state" of the Chinese character of the code and some things conflict, so there are garbled.
Second, the solution:
Use:
Copy Code code as follows:
<a href= "list.php?plate=<?php echo UrlEncode" ("Precinct dynamics");? > "charset=" Utf-8 "target=" main ">[View]</a>
And then use it on the list.php page.
Copy Code code as follows:
<?php
Header ("content-type:text/html; Charset=utf-8 ");
if ($_get[' plate '])
echo $plate =urldecode ($_get[' Plate '));
?>
Also will not garbled and transmission is not normal.
Note that the receive Get page encoding here needs to be consistent with the sender!
About String UrlEncode (string $str) functions
This function makes it easy to encode the string and use it for the request part of the URL, and it also makes it easy to pass the variable to the next page.
Example 1 UrlEncode ()
Copy Code code as follows:
<?php
Echo ' <a href= ' mycgi?foo= ', UrlEncode ($userinput), ' > ';
?>
Example 2 UrlEncode () and Htmlentities ()
Copy Code code 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 your PHP program design.