JP character error in title of XML RSS using simplexml_load_file() php
P粉032900484
P粉032900484 2024-04-03 21:22:05
0
1
383

PHP version: 7.4.30

I use simplexml_load_file php function,

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

xml rss file [example]:

<?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>ˆ

Output title [$rss->channel->item[0]->title] : 2022 Product Expo held in South Africaˆ< /p>

How to get the title: Kobe Digest 2022 Product Expo

P粉032900484
P粉032900484

reply all(1)
P粉729436537

I changed this line to xml rss JP characters to correct it. all is well.

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

to

$feed = file_get_contents($rsses[$i]['url']);
$rss = simplexml_load_string($feed);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!