从 iso-8859-1 到 UTF-8 的整个 RSS Feed

Whole RSS Feed from iso-8859-1 into UTF-8

我正在研究基于 RSS 提要的 Amazon Echo Skill。 此提要采用 iso-8859-1 编码,但需要采用 UTF-8。

因为在我的情况下该技能只需要 <encoded> 标签,所以我尝试了:

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

但这并没有起到任何作用。同样在 header 中,当我通过以下方式加载文件时:

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

它仍然说:<?xml version="1.0" encoding="iso-8859-1"?>

现在我找不到解决这个问题的方法。也许将整个提要更改为 UTF-8。有什么想法吗?

已找到答案。 我加载了提要:

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

并将其编码为:

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

现在对我来说工作得很好。

我还将加载函数更改为:

$xml = new DOMDocument('1.0', 'utf-8');
$xml->loadXML($feed);