PHP __construct() 函数
PHP 教程
· 2019-01-28 23:43:53
实例
函数创建一个新的 SimpleXMLElement 对象,然后输出 body 节点的内容:
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XML;
$xml=new SimpleXMLElement($note);
echo $xml->body;
?>
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XML;
$xml=new SimpleXMLElement($note);
echo $xml->body;
?>
定义和用法
__construct() 函数创建一个新的 SimpleXMLElement 对象。
语法
__construct(data,options,data_is_url,ns,is_prefix);
| 参数 | 描述 |
|---|---|
| data | 必需。形式良好的 XML 字符串或 XML 文档的路径或 URL(如果 data_is_url 是 TRUE)。 |
| options | 可选。规定附加的 Libxml 参数。通过指定选项为 1 或 0(TRUE 或 FALSE,例如 LIBXML_NOBLANKS(1))进行设置。 可能的值:
|
| data_is_url | 可选。如果是 TRUE 表明 data 是 XML 文档的路径或 URL,而不是字符串数据。默认是 FALSE。 |
| ns | 可选。规定命名空间前缀或 URI。 |
| is_prefix | 可选。规定一个布尔值。如果 ns 是前缀则为 TRUE,如果 ns 是 URI 则为 FALSE。默认是 FALSE。 |
技术细节
| 返回值: | 返回表示 data 的 SimpleXMLElement 对象。 |
|---|---|
| PHP 版本: | 5.0.1+ |
| PHP 更新日志: | PHP 5.1.2:新增了 options 和 data_is_url 参数。 PHP 5.2:新增了 ns 和 is_prefix 参数。 |
更多实例
假设我们有如下的 XML 文件,"note.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>
实例 1
从 URL 中创建一个 SimpleXMLElement 对象:
<?php
$xml=new SimpleXMLElement("note.xml",NULL,TRUE);
echo $xml->asXML();
?>
$xml=new SimpleXMLElement("note.xml",NULL,TRUE);
echo $xml->asXML();
?>
点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html
REST in Practice
Jim Webber、Savas Parastatidis、Ian Robinson / O'Reilly Media / 2010-9-24 / USD 44.99
Why don't typical enterprise projects go as smoothly as projects you develop for the Web? Does the REST architectural style really present a viable alternative for building distributed systems and ent......一起来看看 《REST in Practice》 这本书的介绍吧!