我需要解析这个字符串:
<RESPONSE>
<status>200</status>
<credits>100.00</credits>
</RESPONSE>
似乎是XML,但我认为不是。实际上,没有其他标签或其他。
我需要解析并解压缩,所以我可以打印输出,例如,
"<p>Available credits: '.$credits.'</p>"
当然我尝试过SimpleXMLElement,但它无法识别XML。
你能帮帮我吗?
谢谢
答案 0 :(得分:1)
您的XML有效但缺少XML标头。基本上在添加标题后,您应该能够使用SimpleXML:
$xml = "<?xml version='1.0' standalone='yes'?>\n" . $similXML;
$response = new SimpleXMLElement($xml);
echo $response->credits;
答案 1 :(得分:0)
如果您只需要一些静态值,您可以自己提取它们。
要获得学分:
if (preg_match('/<credits>([0-9.]+)<\/credits>/', $response, $matches) {
$credits = $matches[1];
}