在PHP 7中打印XML

时间:2017-07-05 04:42:46

标签: php xml

您好我想在php中打印一个字符串xml(标题)

我试过了:

<?php
$xml = "<tracks>
<radioname>Radio</radioname>
<track>
<uniqueid>400000</uniqueid>
<title>Mask Off</title>
<artists>Future</artists>
</track>
</tracks>";

$xml = simplexml_load_string($xml); 
echo $xml->tracks->track->title;

?>

1 个答案:

答案 0 :(得分:0)

你应该试试这个:

$xml = '<?xml version="1.0" encoding="UTF-8"?><tracks>
<radioname>Radio</radioname>
<track>
<uniqueid>400000</uniqueid>
<title>Mask Off</title>
<artists>Future</artists>
</track>
</tracks>';

$xmlcont = new SimpleXMLElement($xml);

echo $xmlcont->track->title;

输出将是:

Mask Off