I want to write little script returning JSON from all news table in my database. The problem is that json_encode() cant correctly encode polish characters.
<?php
include 'config.php';
$sql="SELECT * FROM news";
$q = mysql_query($sql);
$i = 0;
while($row = mysql_fetch_assoc($q)) {
$row['news_content'] = utf8_encode($row['news_content']);
$row['news_title'] = utf8_encode($row['news_title']);
$tab[$i] = $row;
$i++;
}
$result = json_encode($tab);
echo $result;
?>
When I get from database text with 'ł' character json encodes it into \u00b3 which is "superscript three"
My whole database and tables are set to UTF-8.
Strange (for me) thing is, when I use
$row['news_content'] = utf8_encode($row['news_content']);
then
echo utf8_decode($row['news_content']);
it shows correctly the 'ł' character, but when i decode my json output, it doesnt work..