Home > Article > Backend Development > What should I do if the Chinese characters in the URL obtained by PHP are garbled?
PHP uses get to get the solution to garbled Chinese characters in the URL: use the function [string urlencode (string $str)] to encode the string and use it in the request part of the URL. The code is [echo '< ;a href="mycgi?foo=', url].
##Solution to the garbled Chinese characters in the url obtained by PHP using get:
1. Use: The code is as follows:<a href="list.php?plate=<?php echo urlencode("辖区动态");?>" charset="utf-8" target="main">[查看]</a>Then use on the list.php page and the code is as follows:
<?php header("Content-type: text/html; charset=utf-8"); if($_GET['plate']) echo $plate=urldecode($_GET['plate']); ?>There will be no garbled codes and abnormal transmission. Note that the encoding of the receiving GET page here needs to be consistent with the sending end! 2. About
string urlencode ( string $str ) Function
urlencode()
<?php echo '<a href="mycgi?foo=', urlencode($userinput), '">'; ?>Example 2
urlencode() and
htmlentities()
<?php $query_string = 'foo=' . urlencode($foo) . '&bar=' . urlencode($bar); echo '<a href="mycgi?' . htmlentities($query_string) . '">'; ?>
Related learning recommendations:php programming (video)
The above is the detailed content of What should I do if the Chinese characters in the URL obtained by PHP are garbled?. For more information, please follow other related articles on the PHP Chinese website!