dongwenhui8900 2017-04-06 02:07 采纳率: 0%
浏览 45
已采纳

整个RSS从iso-8859-1进入UTF-8

I'm working on an Amazon Echo Skill, which is based on an RSS feed. This feed is encoded in iso-8859-1, but needs to be in UTF-8.

Because the skill only needs the <encoded> tag in my case, i tried:

  1. $content = $xml->getElementsByTagName("encoded")
  2. ->item($i)->nodeValue;
  3. utf8_encode($content);

But this didn't do anything. Also in the header when i load the file via:

  1. $file = 'old.xml';
  2. $xml = new DOMDocument('1.0', 'utf-8');
  3. $xml->load($file);

It still says: <?xml version="1.0" encoding="iso-8859-1"?>

Now i can't find a way for solving this problem. Maybe change the whole feed to UTF-8. Any ideas?

  • 写回答

1条回答 默认 最新

  • drmq16019 2017-04-09 16:03
    关注

    Answer found. I loaded the feed with:

    $feed = file_get_contents(' .... ');

    and encoded it with:

    1. $feed = utf8_encode($feed);
    2. $feed = str_replace('encoding="iso-8859-1"', 'encoding="utf-8"', $feed);

    Now works fine for me.

    Also i changed the load-function to:

    1. $xml = new DOMDocument('1.0', 'utf-8');
    2. $xml->loadXML($feed);
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部