I'm having trouble decoding Greek text when using ajaxed infinite scrolling. It's the first time I'm dealing with non-English data, but as far as I understand every single Greek character needs to be escaped, because otherwise Ajax breaks trying so send the characters.
I make it Ajax-friendly by escaping it with this (PHP):
function utf8ize($d) { // Encoding workaround
if(is_array($d)) {
foreach ($d as $k => $v) {
$d[$k] = utf8ize($v);
}
} elseif (is_string ($d)) {
return utf8_encode($d);
}
return $d;
}
so this
Το γράμμα άλφα (ἄλφα) είναι το πρώτο γράμμα του ελληνικού αλφαβήτου.
becomes this:
Το γÏάμμα άλφα (ἄλφα) είναι το Ï€Ïώτο γÏάμμα του ÎµÎ»Î»Î·Î½Î¹ÎºÎ¿Ï Î±Î»Ï†Î±Î²Î®Ï„Î¿Ï….
which is how the text looks raw on my UK-locale database. But now I am not sure how to convert it back to Greek on the front-end.
Normally I would successfully decode non Basic Latin words like café, fiancé, façade using PHP's utf8_encode at back-end and then jQuery's decodeURIComponent on front-end, but with Greek this error comes up
URIError: URI malformed
Is there an in-built jQuery function to convert utf-8 into another format that supports Greek at front-end?
This is how it looks on default load:
And this is what happens when I try to inject the same text via Ajax