Jump to content

utf8_encode


bravo14

Recommended Posts

However the Č is still showing as '?', any ideas what I am doing wrong?

 

You didn't read the manual. The function utf8_encode() transcodes a string from ISO 8859-1 to UTF-8. Since your input clearly isn't ISO 8859-1, this function doesn't help you at all.

 

I guess what you actually want is declare the character encoding of the HTML document as UTF-8 so that browsers display it correctly. Put this somewhere on top of your script:

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

In addition to this, you also have to set the encoding of the database connection to UTF-8:

// If you're using PDO, set the character encoding in the DSN string.
$database = new PDO('mysql:host=localhost;dbname=YOURDB;charset=utf8', 'YOURUSER', 'YOURPASSWORD', $options);

// If you're using MySQLi, set the encoding right after the connection
$database->set_charset('utf8');

// If you're still using the old MySQL extension ...
mysql_set_charset('utf8');

Do not use a SET NAMES query. This silently changes the connection encoding without notifying PHP about it. As a result, all escaping functions will continue to use the old encoding and may stop working entirely.

Link to comment
https://forums.phpfreaks.com/topic/288830-utf8_encode/#findComment-1481139
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.