Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.