簡體   English   中英

Facebook應用程序UTF-8 PHP問題

[英]Facebook Application UTF-8 Issues in PHP

我正在使用PHP開發一個Facebook Iframe應用程序,該應用程序從另一個站點打開RSS源並顯示源中的選定項目。 RSS提要,如果UTF-8編碼,但是當我顯示所選項目時,我得到的字符顯示為ISO-8859無論如何。

示例:“不要”而不是“不要”

這是我的工作代碼:

$doc = new DOMDocument();
  $doc->load('https://www.otherwebsite.com/rss.php');

  foreach ($doc->getElementsByTagName('item') as $node) {
            $title = $node->getElementsByTagName('title')->item(0)->nodeValue;
            if ($title == $chinese->getAnimal()){
              $horoscope = $node->getElementsByTagName('description')->item(0)->nodeValue;
           }      
  }    
  echo '

Your horoscope : ' . $horoscope . '

'; }

我使用的是PHP 5.2版。 任何問題或建議都會被感激,我仍然在學習PHP,所以我可能錯過了一些技術嫻熟的從業者。

嘗試

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);

確保您的網頁上有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;

header('Content-Type: text/html; charset=iso-8859-1')

嘗試將其添加到php文件的最頂層。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM