您现在的位置是:首页 > PHP函数

李清波 2015-09-30 PHP函数 1702 复制当前网址

simplexml_load_string



PHP simplexml_load_string() 函数

定义和用法

simplexml_load_string() 函数把 XML 字符串载入对象中。

如果失败,则返回 false。


语法

simplexml_load_file(string,class,options,ns,is_prefix)

参数描述
string必需。规定要使用的 XML 字符串。
class可选。规定新对象的 class。
options可选。规定附加的 Libxml 参数。
ns可选。
is_prefix可选。


返回值

返回类 SimpleXMLElement 的一个对象,该对象的属性包含 XML 文档中的数据。如果失败,则返回 false。


例子

<?php
$xmlstring = <<<XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Dont forget the meeting!</body>
</note>
XML;

$xml = simplexml_load_string($xmlstring);

var_dump($xml);
?>

输出:

object(SimpleXMLElement)#1 (4)
{
["to"]=> string(4) "George"
["from"]=> string(4) "John"
["heading"]=> string(8) "Reminder"
["body"]=> string(29) "Dont forget the meeting!"
}


文章来源:https://www.liqingbo.com/blog-796.html

上一篇:xpath

下一篇:simplexml_load_file

评论