0

I'm developing a rss feed for my site. The problem becomes when I trying to decode the content, some characters are not decoded correctly.

This is my string on my row "html" in my table with utf8_spanish2_ci collation: I save data with utf8_encode.

<p style="text-align: center">Calidad: ⦠BRrip<br />Peso: ⦠693 Mb<br />Duración: ⦠1:33:09 Hs.<br />Codec video: ⦠Xvid<br />Formato: ⦠Avi<br />Resolución: ⦠640 x 272<br />Bitrate del video: ⦠904 Kbps<br />Frame rate: ⦠23.976 fps<br />Idioma: ⦠Español Latino<br />Codec Audio: ⦠MP3<br />Bitrate Audio: ⦠128 Kb/s 44100hz<br />Subtitulos: ⦠No Tiene</p>

The string Outputs: With utf8_decode, some characters are not decoded correctly

<p style="text-align: center">Calidad: �?� BRrip<br />Peso: �?� 693 Mb<br />Duración: �?� 1:33:09 Hs.<br />Codec video: �?� Xvid<br />Formato: �?� Avi<br />Resolución: �?� 640 x 272<br />Bitrate del video: �?� 904 Kbps<br />Frame rate: �?� 23.976 fps<br />Idioma: �?� Español Latino<br />Codec Audio: �?� MP3<br />Bitrate Audio: �?� 128 Kb/s 44100hz<br />Subtitulos: �?� No Tiene</p>

The string should be:

<p style="text-align: center">Calidad: … BRrip<br />Peso: … 693 Mb<br />Duración: … 1:33:09 Hs.<br />Codec video: … Xvid<br />Formato: … Avi<br />Resolución: … 640 x 272<br />Bitrate del video: … 904 Kbps<br />Frame rate: … 23.976 fps<br />Idioma: … Español Latino<br />Codec Audio: … MP3<br />Bitrate Audio: … 128 Kb/s 44100hz<br />Subtitulos: … No Tiene</p>

This is my complete code:

<?php
header('Content-Type: application/rss+xml; charset=utf-8');
echo '<?xml version="1.0" encoding="utf-8"?>';
echo "\n<rss version='2.0'>";
echo "<channel>\n";
echo "<title>Feed Juegos</title>\n";
echo "<link>http://example.com</link>\n";
echo "<description>Ultimas Entradas Xxx Javi</description>\n";

        DEFINE ('USER', 'zadmin_new'); 
        DEFINE ('PWW', 'mierda');  
        DEFINE ('HOST_BD', 'localhost');  
        DEFINE ('DBNAME', 'zadmin_warezo'); 

        $conexion = mysql_connect(HOST_BD, USER, PWW) or  
        die ('No se pudo conectar a la BD');  
        mysql_select_db(DBNAME) or die ('Error in connection');  

        $query= "SELECT * FROM posts WHERE id_cat = 6 ORDER BY posts.fecha DESC LIMIT 0,18";
        $result = mysql_query($query) or die ('ERROR IN QUERY');  

        while ($fila = mysql_fetch_array($result, MYSQL_ASSOC))
        {
            $desc = $fila['html'];
            echo "<item>\n";
            echo "<title>".$fila['titulo']."</title>\n";
            echo "<link>http://example.com/peliculas-series/2/".$fila['id']."/".$fila['slug'].".html</link>\n";  
            echo "<description>
".$desc."
</description>";          
            echo "</item>\n";

        }  
    echo "</channel>";
    echo "</rss>";
?>
Paulo Freitas
  • 13,194
  • 14
  • 74
  • 96
jose sanchez
  • 339
  • 4
  • 12
  • possible duplicate of [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – deceze Dec 17 '13 at 21:28
  • Please follow [this guide](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through). Make sure that **all** parts of your application use UTF8. Don't use `utf8_(de|en)code` unless you know what you're doing. Their names are misleading! – ComFreek Dec 17 '13 at 21:28
  • What are you using `utf8_encode` for? Read http://kunststube.net/encoding – deceze Dec 17 '13 at 21:29
  • deceze and ComFreek the link that you provide not solves my problem.. whit that class the output string contains some question symbols...any idea ?, you can check http://zonadictoz.biz/robot/rss-peliculas.php – jose sanchez Dec 17 '13 at 22:11

1 Answers1

0

use htmlentities() and html_entity_decode() instead

store the text with the special characters after usinh htmlentities()

$text = htmlentities("çéà"); // resulting in $text = "&ccedil;&eacute;&agrave;";

After retriving it from the db just use html_entity_decode()

html_entity_decode($text); // resulting in çéà

no need for utf8 staff

hope this helps

ghousseyn
  • 102
  • 4
  • 1
    Please explain what those functions do, possibly with an example or two, and why they are better. – rgettman Dec 17 '13 at 22:07