Returnere forkert charset?
Hej Eksperter.Jeg har et php script som returnere nogle varer fra min database, herefter kan man andetsteds via Ajax søge i disse.
Mit problem er at varer med æ, ø og å bliver vist som et sort firkantet spørgsmålstegn. Hvorledes fikses dette?
På forhånd tak.
<?php
include "../lib/mysql/mysql.php";
$query_on_key = mysql_query("SELECT id, producer, product_name FROM articles") or die(mysql_error());
while($key_results = mysql_fetch_array($query_on_key)){
$id = (int) $key_results['id'];
$producer = $key_results['producer'];
$product_name = $key_results['product_name'];
$aProducts[] = $product_name;
$aProducer[] = $producer;
}
$input = strtolower( $_GET['input'] );
$len = strlen($input);
$limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 8;
$aResults = array();
$count = 0;
if ($len)
{
for ($i=0;$i<count($aProducts);$i++)
{
if (strtolower(substr(utf8_decode($aProducts[$i]),0,$len)) == $input)
{
$count++;
$aResults[] = array( "id"=>($i+1) ,"value"=>htmlspecialchars($aProducts[$i]), "info"=>htmlspecialchars($aProducer[$i]) );
}
if ($limit && $count==$limit)
break;
}
}
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache"); // HTTP/1.0
if (isset($_REQUEST['json']))
{
header("Content-Type: application/json");
echo "{\"results\": [";
$arr = array();
for ($i=0;$i<count($aResults);$i++)
{
$arr[] = "{\"id\": \"".$aResults[$i]['id']."\", \"value\": \"".$aResults[$i]['value']."\", \"info\": \"\"}";
}
echo implode(", ", $arr);
echo "]}";
}
else
{
header("Content-Type: text/xml; charset=utf-8");
echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?><results>";
for ($i=0;$i<count($aResults);$i++)
{
echo "<rs id=\"".$aResults[$i]['id']."\" info=\"".$aResults[$i]['info']."\">".$aResults[$i]['value']."</rs>";
}
echo "</results>";
}
?>
