Im storing text in a DB as UTF8.
When a post is sent via JS to my API, such symbols as ö come back as "ö"
My website html is declared as
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
My API output is sent out with a header declaring utf-8, like so:
$status_header = 'HTTP/1.1 '.$status.' '.self::getStatusCodeMessage($status);
header($status_header);
header('Content-type: ' . $content_type.'; charset=utf-8');
if ($body !== '') {
echo $body;
The only way I've managed to get round this is by using PHP on my output todo this:
private static function fixText($text) {
$replaceChars = array(
"“" => "\"",
'•' => '·',
"â€" => "\"",
"’" => "'",
'ö' => 'ö',
'â€' => "'",
"é" => "é",
"ë" => "ë",
"£" => "£"
);
foreach($replaceChars as $oldChar => $newChar) {
$text = str_replace($oldChar, $newChar, $text);
}
$text = iconv("UTF-8", "UTF-8//IGNORE", $text);
return $text;
}
Obviously this is not ideal as I have to keep adding more and more symbols to the map.
UPDATE:
A developer had sneakily added this code:
$document->text = mb_convert_encoding($document->text, mb_detect_encoding($document->text), "cp1252");
As a way to overcome old latin characters coming through damaged.