0

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

EasyBB
  • 6,176
  • 9
  • 47
  • 77
  • did you make sure your db tables are utf-8 as well? You need to ensure the ENTIRE rendering pipeline is utf-8. client->server->mysql->table->php->client – Marc B May 11 '14 at 03:18
  • but why when I don't even call the sql db at all what so ever...? – EasyBB May 11 '14 at 03:19
  • well, where's this text coming from? are you sure it's utf-8? what about utf-16? – Marc B May 11 '14 at 03:20
  • It's coming from response_class.php – EasyBB May 11 '14 at 03:23
  • which means nothing to us. that's like saying "it comes from planet earth" – Marc B May 11 '14 at 03:24
  • lol. It's a php object class. functions with arrays. I just tested the sql db and it responded with `Current character set: utf8` – EasyBB May 11 '14 at 03:25
  • here see what is happend --> http://minjs.site88.net/l18n_js.php?lang=es you can change the lang to `en` to see the english version – EasyBB May 11 '14 at 03:26
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/52449/discussion-between-easybb-and-marc-b) – EasyBB May 11 '14 at 03:27

1 Answers1

0

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.

Community
  • 1
  • 1
charmeleon
  • 2,693
  • 1
  • 20
  • 35
  • I've done all of that except the php.ini since I don't have one specifically. Still nothing- but I can try the entities one – EasyBB May 11 '14 at 03:35
  • With the htmlentities I got this: `'no se puede':{` which is way wrong... I should mention that in the `l18n_js.php` I have the header as `header("content-type: application/x-javascript");` – EasyBB May 11 '14 at 03:36
  • nevermind it's coming out perfectly fine when I use it as an actual js file and not when I go to the js file itself it's weird but whatever. Sorry guys – EasyBB May 11 '14 at 03:44