[英]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.