0

I'm having issue with storing Swedish characters in DB, so I tried everything possible, and nothing worked. As the last option, I decided to store every Swedish character as HTML entity, using function like:

function fix_swed_chars($s){
    $s = trim($s, " \n\t\r");
    $ss = "";

    for($i = 0; $i < strlen($s); $i++){

        $x = ord($s[$i]);

        if ($x > 125){
            if ($x != 160)
                $ss .= "&#$x;";
            else $ss .= " ";
        } else $ss .= $s[$i];
    }

    return trim($ss);
} 

That works just fine in some cases, but here is he issue: "Äntligen" for example is stored as "&#195;&#132;ntligen" which means that "Ä" is actually recognized by php as 2 characters.

Edwin
  • 1
  • 2
  • 1
    What DB system are you using? – Marco Mar 14 '18 at 00:50
  • 1
    Because you're trying to store and/or display UTF8-encoded data as something not-UTF8. https://stackoverflow.com/questions/279170/utf-8-all-the-way-through – Sammitch Mar 14 '18 at 00:54
  • Is your PHP document saved as UTF-8? – StackSlave Mar 14 '18 at 00:58
  • DB is MySQL and in this case what I'm trying to store/display is html entity that represents "Ä", which should be a single html entity (like: XX;). Such html entity should be stored with no issue in any DB char-set. The issue here is: why i'm getting 2 html entities for a single character instead of 1 html entity? – Edwin Mar 14 '18 at 02:35

0 Answers0