Hallo, Als ik met mijn php script een rss feed binnen haal, geeft hij de accenten niet goed weer.

Hieronder een voorbeeld hoe het er uit ziet als ik de feed binnen haal.
Crisis zorgt voor stortvloed aan financiële spam

Zo zou ik het graag willen hebben.
Crisis zorgt voor stortvloed aan financiële spam


<?php
$xml = simplexml_load_file('http://feeds.feedburner.com/computeridee_nieuws');

foreach($xml->channel->item as $item)
{
    echo '<h1>' .  $item->title . '</h1>';
    echo '<div>' . $item->description . '</div>';
}
?>

Dat zijn unicode karakters. Die karakters gebruiken elk 16 bit aan informatie, terwijl de klassieke ASCII karakters slechts 8 bit aan informatie hebben.


Nu kan je twee kanten op: ofwel zet je alles in unicode, of je decodeert de strings in de variabelen naar ascii.

manier 2:
bv.
<?php
$item->title = utf8_decode( $item->title );
$item->description = utf8_decode( $item->description );
...
?>

manier 1: iets lastiger:
in je html hoofding zet je:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

Vooraleer je html naar de gebruiker stuurt, voeg je deze lijn code toe:
header("Content-Type: text/html; charset=utf-8");

dat wordt dus iets als
<?php
header("Content-Type: text/html; charset=utf-8"); //
echo'<!DOCTYPE ...
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
...
</head>
<body>
...
';?>
Hoi Emmanuel, Bedankt voor je goede uitleg, werkt goed.
Gr Els
Een andere vraag en ik denk dat dit hier wel kan.
Bij mij komt de content uit een database alleen ziek ik deze niet verschijnen.
Ik doe wellicht helemaal wat fout maar goed al doende leer je.
Zou iemand kunnen zeggen wat aan onderstaande code niet goed is?
De RSS pagina kan je hier vinden: http://www.plusbeaus.nl/rss/rss.php

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
session_start();
// databse connectie importeren

//header("Content-Type: application/xml; charset=UTF-8");
//header("Content-Type: text/html; charset=utf-8");

//content-type
header('Content-type: application/rss+xml; charset=iso-8859-1');

//yes it's xml
echo '<?xml version="1.0" encoding="iso-8859-1"?>';

//rss start
echo '<rss version="2.0">';

echo '<channel><title>www.plusbeaus.nl | RSS FEED</title><link>http://www.plusbeaus.nl</link><description>plusbeaus laatste nieuws</description><language>nl</language><pubDate>date</pubDate>';

//$sql = mysql_query("SELECT * FROM newsflash ORDER BY 'Date' ASC LIMIT 0,500") or trigger_error(mysql_error());
$sql = mysql_query("SELECT * FROM newsflash") or trigger_error(mysql_error());

while($show = mysql_fetch_object($sql))
{
echo '<item><title>' . $show->Naam . '</title><link>http://www.plusbeaus.nl</link><pubDate>'; . $show->Date . '</pubDate><description>' . $show->Bericht . '</description></item>';
}
echo '</channel></rss>';

?>

Reageren