PHP Adopts get to Obtain url Chinese Character Garbled Code Solution

  • 2021-08-03 09:21:12
  • OfStack

In this paper, an example is given to describe the solution to the garbled code of url Chinese characters obtained by PHP using get. Share it for your reference. The specific methods are as follows:

1. Issues:

It was intended to be used like this

<a href="list.php?plate= Dynamics of jurisdiction " charset="utf-8" target="main">[ View the developments in the jurisdiction ]</a>

The result is obtained on the list. php page-view [jurisdiction movement]
1 began to guess that the code of "state" of Chinese characters might conflict with something, so there was garbled code.

2. Solution:

Use:

<a href="list.php?plate=<?php echo urlencode(" Dynamics of jurisdiction ");?>" charset="utf-8" target="main">[ View ]</a>

Then use this on the list. php page

<?php
header("Content-type: text/html; charset=utf-8");
if($_GET['plate'])
echo $plate=urldecode($_GET['plate']);
?>

There will be no garbled code and abnormal transmission.
Note that the receiving GET page coding here needs to be matched with the sending end 1!

About string urlencode (string $str) Function

This function makes it easy to encode a string and use it in the request part of URL, and it also makes it easy to pass variables to the next page.
Example 1 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) . '">';
?>

I hope this article is helpful to everyone's PHP programming.


Related articles: