Jump to content

Recommended Posts

Welp, I've encountered an error this time... Certain characters don't seemed to be displayed when I echo the data in PHP file. For example, the mdash (—) and the a with a tilde (which is necessary for certain places such as São Paulo). These show up as . Is there any way to get them to show normally? I've tried surrounding them with `'s and putting \'s in front of them, but I can't seem to find out how to get them to work.

Link to comment
https://forums.phpfreaks.com/topic/273713-certain-characters-not-showing-up/
Share on other sites

The functions you use in PHP to manipulate the data have to be UTF-8 compatible as well, yes.

Though this is only true for the functions that actually manipulate the string data that contains UTF-8 characters, it's better to treat all strings as if they were UTF-8. That way you are ensured that you will not encounter any future bugs, related to differing charsets.

 

That said, I suspect there are one or two places where you've might have forgotten to define the proper charset:

  • On the database connection, with *_set_charset ().
  • In the HTTP headers themselves, with the proper header () call.

 

The latter one is necessary because the meta-HTML headers are ignored by the browser, if they conflict with a HTTP header. So if your web-server is set to serve HTML as ISO-8859-1 by default (which a lot of them are), then your "meta http-equiv" HTML header is quite ineffective.

 

I also recommend reading the article "The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)". As it says: It's the absolute minimum, and no excuses! :P

The functions you use in PHP to manipulate the data have to be UTF-8 compatible as well, yes.

Though this is only true for the functions that actually manipulate the string data that contains UTF-8 characters, it's better to treat all strings as if they were UTF-8. That way you are ensured that you will not encounter any future bugs, related to differing charsets.

 

That said, I suspect there are one or two places where you've might have forgotten to define the proper charset:

  • On the database connection, with *_set_charset ().
  • In the HTTP headers themselves, with the proper header () call.

 

The latter one is necessary because the meta-HTML headers are ignored by the browser, if they conflict with a HTTP header. So if your web-server is set to serve HTML as ISO-8859-1 by default (which a lot of them are), then your "meta http-equiv" HTML header is quite ineffective.

 

I also recommend reading the article "The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)". As it says: It's the absolute minimum, and no excuses! :P

Thanks.  I tried this:

/* change character set to utf8 */
if (!mysqli_set_charset($con, "utf8")) {
    printf("Error loading character set utf8: %s\n", mysqli_error($con));
} else {
    printf("Current character set: %s\n", mysqli_character_set_name($con));
}

to test, and the output was "Error loading character set utf8:"  I don't understand.

Me using the * in the function name like that, and linking to the MySQLI version, was a subtle hint to tell you that:

  1. I don't know what library you're using to communicate with the database.
  2. And in any case, you really should be using MySQLI or PDO.

 

Since you got the error message, I'm assuming that you're still using the old and outdated mysql library. I recommend updating your scripts to use the current libraries, before the old one is completely removed from PHP. Alternatively, use the old mysql_* version of the function, in the meantime.

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.