Question

I am having problems with my code setting the utf-8

I have set

header('Content-Type: text/html; charset=utf-8');

I also tried

ini_set('default_charset','utf-8');

I have not tried

$mysqli->set_charset("utf8")

as I am not even connecting to the sql database. I have five files

core.php l18n.php l18n_js.php lang.php and response_class.php

Core calls l18n.php and response_class.php

Then we have lang.php which is a dummy webpage with the meta charset already set to utf-8 and it calls to l18n_js.php and it has core.php included with it which then returns the correct language file.

I am telling you what is going on as to ask do I need to set the header on each of the php files, as well as ini_set I am having so much difficulty making sure it is encoded to utf-8 and not show characters like ó él te h all messed up

Was it helpful?

Solution

Please see this previous answer for how to configure PHP to handle UTF-8. If it still doesn't work, anywhere that you expect UTF-8 output from your database, use

htmlentities($foobar, ENT_QUOTES, 'UTF-8');

The last parameter is optional if you are running PHP >= 5.4.0, but I always include it for backwards compatibility.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top