SimpleXml元素:特殊字符错误

时间:2011-12-09 07:21:09

标签: php character-encoding simplexml

我使用simpleXml来解析我的xml,但是当我尝试解析西班牙语,法语,爱沙尼亚语,葡萄牙语,上标或下标时,它总是打破页面。

任何想法?

XML示例: -

<carddata> <logo_id>0</logo_id> <cscale>Ñ</cscale><carddata>

脚本: -

$carddetail = new SimpleXMLElement($xml);
$carddetail = iconv('UTF-8', 'ISO-8859-15//TRANSLIT', $carddetail);

在我发送的xml中

<cscale><![CDATA[Peter Nortoné]]></cscale> 

,错误是:

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 22: parser error : CData section not finished Peter Nort in D:\xampp\htdocs\logosnap\card.php on line 144

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: <text><\![CDATA[Peter Norton in D:\xampp\htdocs\logosnap\card.php on line 144

1 个答案:

答案 0 :(得分:1)

$carddetail = new SimpleXMLElement($xml);  
<-- this set $carddetail as simplexmlelement object

您不能将对象用作字符串,如: -

$carddetail = iconv('UTF-8', 'ISO-8859-15//TRANSLIT', $carddetail);

所以,试试这个: -

$carddetail = new SimpleXMLElement(iconv('UTF-8','ISO-8859-15//TRANSLIT',$xml));