首頁  >  問答  >  主體

使用 simplexml_load_file() php,XML RSS 的標題出現 JP 字元錯誤

PHP 版本:7.4.30

我使用 simplexml_load_file php 函數,

$rss = simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA);

xml rss 檔案[範例]:

<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
<channel>
<title>AAA</title>
<link>https://aaa.com</link>
<description>description</description>
<item>
    <title>PRODUCTS EXPO 2022 in 神戸 ダイジェスト</title>
</item>
</channel>
</rss>ˆ

輸出標題[$rss->channel->item[0]->title] : 2022年產品博覽會在南非舉行ˆ< /p>

#如何取得標題:神戶文摘2022年產品博覽會

P粉032900484P粉032900484179 天前328

全部回覆(1)我來回復

  • P粉729436537

    P粉7294365372024-04-04 20:20:31

    我將此行更改為 xml rss JP 字元以進行更正。 一切都很好。

    $rss = simplexml_load_file($rsses[$i]['url'], 'SimpleXMLElement', LIBXML_NOCDATA);

    $feed = file_get_contents($rsses[$i]['url']);
    $rss = simplexml_load_string($feed);

    回覆
    0
  • 取消回覆