我正在使用PHP开发一个Facebook Iframe应用程序,该应用程序打开来自另一个站点的RSS提要并显示来自提要的选定项目。RSS提要是UTF-8编码的,但是当我显示所选项目时,我得到的字符显示为ISO-8859等等。
示例:用"don
你的星座: '。美元的星座。'
';}>之前我使用的PHP版本5.2。任何问题或建议,我将感激地接受,我仍在学习PHP,所以我可能错过了一些明显的更熟练的从业者
确保你的网页上有一个适合UTF-8的html标题和元数据,即:
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1//EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='eng' lang='en'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>WAMP</title>
<meta name='Description' content='Website Under Construction' />
</head>
<body>
CONTENT
</body>
</html>
在回显之前也尝试将字符串转换为UTF-8。
$horoscope = utf8_encode("Your Horoscope : $horoscope");
echo $horoscope;
Try
echo 'Your horoscope : ' . utf8_encode($horoscope);
但是这只适用于ISO-8859-1。
或者试一试
$in_encoding = "ISO-8859-1"; //replace with the encoding of the RSS feed
echo 'Your horoscope : ' . iconv($in_encoding, "UTF-8", $horoscope);
header('Content-Type: text/html; charset=iso-8859-1')