encoding

Problem with UTF-8 and swedish åäö

If you have trouble storing åäö in a UTF-8 mysql database.
make sure field, table and database is utf8_general_ci
Check mysql varaibles by running the following mysql command:

SHOW VARIABLES LIKE "character%";

##
Variable_name            Value
character_set_client    utf8
character_set_connection   utf8
character_set_database    utf8
character_set_filesystem   binary
character_set_results    utf8
character_set_server    latin1
character_set_system    utf8
character_sets_dir    /usr/share/mysql/charsets/

Make sure the above is UTF-8
try setting utf8

utf-8, htmlentities and htmlspecialchars in RSS feeds

Writing an RSS feed based on HTML can cause some trouble using htmlentities though it converts too much, use htmlspecialchars instead.

First: The utf8_function function converts from ISO 8859-1 to UTF-8. So you only need this function, if your input encoding/charset is ISO 8859-1. But why don’t you use UTF-8 in the first place?

Second: You don’t need htmlentities. You just need htmlspecialchars to replace the special characters by character references. htmlentities would replace “too much

Check if string is UTF-8

Have not tested it...

function check_utf8($str) {
$len = strlen($str);
for($i = 0; $i < $len; $i++){
$c = ord($str[$i]);
if ($c > 128) {
if (($c > 247)) return false;
elseif ($c > 239) $bytes = 4;
elseif ($c > 223) $bytes = 3;
elseif ($c > 191) $bytes = 2;
else return false;
if (($i + $bytes) > $len) return false;
while ($bytes > 1) {
$i++;
$b = ord($str[$i]);
if ($b < 128 || $b > 191) return false;