Handling unicode values in GET parameters with PHP
I have the following script test on my server:
<?php echo "Test is: " . $_GET['test']; ?> If I call it with a URL like example.com/script.php?test=ɿ (ɿ being a multibyte character), the resulting page looks like this:
Test: É¿
If I try to do something with a value in $ _GET ['test'], for example, save it in the mysql database, I have the same problem. What do I need to do so that PHP correctly processes this value?
Did you tell the user agent that your HTTP response is UTF-8?
header ('Content-type: text/html; charset=utf-8'); You can also make sure your HTML markup also declares an encoding, for example.
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> Are your tables and mysql client settings configured for UTF-8 in your database? If you test your database using the mysql command-line client, will your terminal environment be configured to wait for UTF-8?
In short, you should check every step: from the source data, the code that affects it, the storage systems that store it, and the tools you use to display and debug.
UTF-8 to the end ...
Follow these steps, in particular:
SET NAMES 'utf8'when connecting to MySQL DB<meta http-equiv="Content-Type" content="text/html; charset=utf-8">in your HTML
By inserting a URL in a browser that contains high utf8 characters, the browser will transcode utf8 characters into a multibyte sequence compatible with RFC 3986, and you will not get utf8 characters in php.
BUT, php will receive and display utf8 characters from url correctly if the page that calls your url is encoded by utf8.
Try calling your php for the test like this:
<iframe src="example.com/script.php?test=ɿ" height="100" width="100" border="1"></iframe>