$xml =<<< XML
<MCS-ENVELOPE type='noteRequest' detail='onlyTitle' username='001' password='' fileID='1'> </MCS-ENVELOPE>
XML;$x = simplexml_load_string($xml);
print_r($x);out:
SimpleXMLElement Object
(
[@attributes] => Array
(
[type] => noteRequest
[detail] => onlyTitle
[username] => 001
[password] =>
[fileID] => 1
) [0] =>
)
<MCS-ENVELOPE type='noteRequest' detail='onlyTitle' username='001' password='' fileID='1'> </MCS-ENVELOPE>
XML;$x = simplexml_load_string($xml);
print_r($x);out:
SimpleXMLElement Object
(
[@attributes] => Array
(
[type] => noteRequest
[detail] => onlyTitle
[username] => 001
[password] =>
[fileID] => 1
) [0] =>
)
$string = <<< XML
<MCS-ENVELOPE type='noteRequest' detail='onlyTitle' username='001' password='' fileID='1'>
</MCS-ENVELOPE>
XML;$xml = simplexml_load_string($string); foreach($xml->attributes() as $name => $value) {
echo $name,'="',$value,"\"\n";
}
?>
没用过simplexml_load_string
$str = <<<XML
<MCS-ENVELOPE type='noteRequest' detail='onlyTitle' username='001' password='' fileID='1'>
</MCS-ENVELOPE>
XML;
$xml = simplexml_load_string($str);
print_r($xml);
?>
有空去手册查查<<<这个符号是什么.
其实
$xml = "<MCS-ENVELOPE type='noteRequest' detail='onlyTitle' username='001' password='' fileID='1'> </MCS-ENVELOPE>
";
是一样的
simplexml_load_string 需要php5环境
非win32环境需要安装 simplexml 扩展
唉!我该怎么办啊!都在催我啊!!!
什么是PHP5环境!?我如何安装simplexml扩展!
$data = <<<XML
<?xml varsion='1.0'?>$data
XML;
这样处理下,现在就可以正常使用
simplexml_load_string($data)
了。