PHP:如何解析一个simil - XML字符串? [重复]

This question already has an answer here:

I need to parse this string:

<RESPONSE>
<status>200</status>
<credits>100.00</credits>
</RESPONSE>

It seems XML but I think that it is not. In effect, no other tags or other.

I need to parse and extract the , so I can print an output, for example,

"<p>Available credits: '.$credits.'</p>"

Of course I tried SimpleXMLElement but it doesn't recognize the XML.

Could you help me?

Thank you

</div>

Your XML is valid but lacks XML header. Basically after you add the header you should be able to use SimpleXML:

$xml = "<?xml version='1.0' standalone='yes'?>
" . $similXML;

$response = new SimpleXMLElement($xml);

echo $response->credits;

If you only need a few static values you can extract them yourself.

To get the credits you would do:

if (preg_match('/<credits>([0-9.]+)<\/credits>/', $response, $matches) {
  $credits = $matches[1];
}