Definition and Usage
定义和用法
The simplexml_load_string() function loads an XML string into an object.
simplexml_load_string()函数的作用是:将一个XML字符串装载入一个对象中。
This function returns FALSE on failure.
如果函数执行失败,将返回False。
Syntax
语法
simplexml_load_string(string,class,options,ns,is_prefix) |
Parameter参数 | Description描述 |
string | Required. Specifies the XML string to use 必要参数。指定需要使用的XML字符串 |
class | Optional. Specifies the class of the new object 可选参数。指定新对象的类 |
options | Optional. Specifies additional Libxml parameters. Is set by specifying the option and 1 or 0 (TRUE or FALSE, e.g. LIBXML_NOBLANKS(1)) 可选参数。指定附加的xml库[Libxml]参数。通过设置0或1指定(True或False,如:LIBXML_NOBLANKS(1)) Possible values: 可能值: - LIBXML_COMPACT - Set small nodes allocation optimization. This may improve the application performance
LIBXML_COMPACT –设置小节点的最优化配置 - LIBXML_DTDATTR - Set default DTD attributes
LIBXML_DTDATTR –设置默认的DTD属性 - LIBXML_DTDLOAD - Load external subset
LIBXML_DTDLOAD –装载额外的子集 - LIBXML_DTDVALID - Validate with the DTD
LIBXML_DTDVALID – 验证DTD有效性 - LIBXML_NOBLANKS - Remove blank nodes
LIBXML_NOBLANKS – 删除空节点 - LIBXML_NOCDATA - Set CDATA as text nodes
LIBXML_NOCDATA – 将CDATA设置为文本节点 - LIBXML_NOEMPTYTAG - Change empty tags (e.g. <br/> to <br></br>), only available in the DOMDocument->save() and DOMDocument->saveXML() functions
LIBXML_NOEMPTYTAG – 改变空的制表符[tag](诸如:将<br/>改变为<br></br>),仅在DOMDocument->save()函数和DOMDocument->saveXML()函数中有效 - LIBXML_NOENT - Substitute entities
LIBXML_NOENT –实体替代品 - LIBXML_NOERROR - Do not show error reports
LIBXML_NOERROR –不显示错误报告 - LIBXML_NONET - Stop network access while loading documents
LIBXML_NONET –装载文档时停止访问网络 - LIBXML_NOWARNING - Do not show warning reports
LIBXML_NOWARNING –不显示警告提示 - LIBXML_NOXMLDECL - Drop the XML declaration when saving a document
LIBXML_NOXMLDECL – 当存储一个文档时放弃XML声明 - LIBXML_NSCLEAN - Remove excess namespace declarations
LIBXML_NSCLEAN –删除多余的名称空间[namespace]声明 - LIBXML_XINCLUDE - Use XInclude substitution
LIBXML_XINCLUDE – 使用XInclude替代 - LIBXML_ERR_ERROR - Get recoverable errors
LIBXML_ERR_ERROR –获取可纠正的错误 - LIBXML_ERR_FATAL - Get fatal errors
LIBXML_ERR_FATAL –获取重大错误 - LIBXML_ERR_NONE - Get no errors
LIBXML_ERR_NONE –不获取错误 - LIBXML_ERR_WARNING - Get simple warnings
LIBXML_ERR_WARNING –获取简单警告 - LIBXML_VERSION - Get libxml version (e.g. 20605 or 20617)
LIBXML_VERSION –获取XML库[libxml]版本(如:20605 或 20617) - LIBXML_DOTTED_VERSION - Get dotted libxml version (e.g. 2.6.5 or 2.6.17)
LIBXML_DOTTED_VERSION –获取libxml点阵版本(如:2.6.5 或 2.6.17) |
ns | Optional 可选参数 |
is_prefix | Optional 可选参数 |
Example
案例
<?php
$xmlstring = <<<XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XML; $xml = simplexml_load_string($xmlstring); var_dump($xml);
?> |
The output of the code above will be:
上述代码将输出下面的结果:
object(SimpleXMLElement)#1 (4)
{
["to"]=> string(4) "Tove"
["from"]=> string(4) "Jani"
["heading"]=> string(8) "Reminder"
["body"]=> string(29) "Don't forget me this weekend!"
} |