如何将xml标题与“<! - ?xml”放在php - >中

时间:2013-07-29 07:44:13

标签: php simplexml

首先:我是SimpleXMLElement对象的新手,所以也许我做错了。

我必须加载此字符串:

$xmlTipologie=simplexml_load_string(html_entity_decode("<?xml version='1.0' encoding='utf-8'?><content>".$temp_dom->saveHTML()."</content>", null, "UTF-8"));

但这是我得到的错误:

Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : StartTag: invalid element name in ....content/plugins/soap-SGS/soap-SGS.php on line 115

如果不添加xml的标头,我会收到此错误。 也许有另一种方法可以在php字符串中添加xml的标题,如果有,我会很高兴你在下面写的,但现在我很好奇另一件事:

我怎样才能把这个字母 - &gt; php字符串中的<?? “在php.ini上设置短标签模式时很明显吗?”

编辑,我用这种方式使用htmlspecialchars:

    $xmlTipologie=simplexml_load_string("<?xml version='1.0' encoding='utf-8'?>".htmlspecialchars("<content><![CDATA[".$temp_dom->saveHTML()."]]></content>",ENT_QUOTES));

这是新的错误:

  

警告:simplexml_load_string()[function.simplexml-load-string]:   实体:第1行:解析器错误:期望开始标记,'&lt;'找不到   /Users/paolo.cargnin/Sites/happycamp/wp-content/plugins/soap-SGS/soap-SGS.php   在第116行

......我无法调试它,这对我造成很大伤害。

由于

2 个答案:

答案 0 :(得分:2)

PHP

<?php
$string = <<<XML
<?xml version='1.0'?> 
<content>
Call function here
</content>
XML;

$xml = simplexml_load_string($string);

print_r($xml);
?>

答案 1 :(得分:1)

我认为您可以使用htmlspecialchars

$xmlTipologie=simplexml_load_string(html_entity_decode(htmlspecialchars("<?xml version='1.0' encoding='utf-8'?><content>".$temp_dom->saveHTML()."</content>"), null, "UTF-8"));