[英]RSS from MySQL - issue with special characters
<?php
header('Content-type: text/xml; charset=utf-8');
DEFINE ('DB_USER', 'root');
DEFINE ('DB_PASSWORD', '');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'rss');
$output = '<?xml version="1.0" encoding="UTF-8"?>';
$output .= '<rss version="2.0">';
$output .= '<channel>';
$output .= '<title>Feed Demo</title>';
$output .= '<description>News Feed from MySQL test.</description>';
$output .= '<language>de</language>';
$connection = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die('-');
mysql_select_db(DB_NAME) or die ('-');
$query = "SELECT * FROM entry ORDER BY date DESC";
$result = mysql_query($query) or die ('-');
while($row = mysql_fetch_array($result)) {
extract($row);
$output .= '<item>';
$output .= '<title>' . $title . '</title>';
$output .= '<description>' . $description . '</description>';
$output .= '<link>' . $link . '</link>';
$output .= '<pubDate>' . date("d. F Y, H:i", strtotime($date)) . '</pubDate>';
$output .= '</item> ';
}
$output .= '</channel>';
$output .= '</rss>';
echo($output);
?>
你好! 我正在使用上面的代码从MySql数据库生成rss提要。 效果很好,直到我在条目中添加特殊字符,例如:,/,ä,ö,ü,ß,?,“等。得到消息
此页面包含以下错误:
377行1上的错误:编码错误带有特殊字符的行之前的所有内容均正确显示。
您应该使用utf8_encode()
对所有值进行编码。
就像是:
while($row = mysql_fetch_array($result)) {
extract($row);
$output .= '<item>';
$output .= '<title>' . utf8_encode($title) . '</title>';
$output .= '<description>' . utf8_encode($description) . '</description>';
$output .= '<link>' . $link . '</link>';
$output .= '<pubDate>' . date("d. F Y, H:i", strtotime($date)) . '</pubDate>';
$output .= '</item> ';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.