How to set the charset to UTF-8 for a received http variable in PHP?
I have a html form using the POST
methode with 1 input field. But when i submit the form and echo the retrieved the contents from the input field via $_POST['input_name']
i get this: KrkiÄ - but i entered (and i need) this: Krkič
So how can i fix this?
I figured it out now. :)
If i want to add the contents to MYSQL then i need to add this:
if(!$mysqli->set_charset("utf8")){
printf("Error loading character set utf8: %s\n",$mysqli->error);
}
If i just need to echo the contents then adding this meta tag
<meta charset="utf-8">
into html head is enough.
There is no global default charset in PHP -- lots of things are encoding-aware, and each needs to be configured independently.
mb_internal_encoding
applies only to the multibyte string family of functions, so it has an effect only if you are already using them (you need to do so most of the time that you operate on multibyte text from PHP code).Other places where an incorrectly set encoding will give you problems include:
Each of these needs to be addressed independently, and most of the time they also need to agree among themselves.
Therefore, it is not enough to say "I want to display some characters". You also need to show how you are displaying them, where they are coming from and what the advertised encoding is for your HTML.
on top of your
php
file place thisyou can use: