dongyuluan7494 2013-12-17 21:26
浏览 83

UTF8_DECODE字符串中的错误解码(符号)

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 "
<rss version='2.0'>";
echo "<channel>
";
echo "<title>Feed Juegos</title>
";
echo "<link>http://example.com</link>
";
echo "<description>Ultimas Entradas Xxx Javi</description>
";

        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>
";
            echo "<title>".$fila['titulo']."</title>
";
            echo "<link>http://example.com/peliculas-series/2/".$fila['id']."/".$fila['slug'].".html</link>
";  
            echo "<description>
".$desc."
</description>";          
            echo "</item>
";

        }  
    echo "</channel>";
    echo "</rss>";
?>
  • 写回答

1条回答 默认 最新

  • douchen2595 2013-12-17 21:40
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100