PHP __construct() 函數(shù)
PHP __construct() 函數(shù)
實(shí)例
函數(shù)創(chuàng)建一個(gè)新的 SimpleXMLElement 對(duì)象,然后輸出 body 節(jié)點(diǎn)的內(nèi)容:
<?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;
?>
運(yùn)行實(shí)例 ?
定義和用法
__construct() 函數(shù)創(chuàng)建一個(gè)新的 SimpleXMLElement 對(duì)象。
語(yǔ)法
__construct(data,options,data_is_url,ns,is_prefix);
參數(shù) | 描述 |
---|---|
data | 必需。形式良好的 XML 字符串或 XML 文檔的路徑或 URL(如果 data_is_url 是 TRUE)。 |
options | 可選。規(guī)定附加的 Libxml 參數(shù)。通過(guò)指定選項(xiàng)為 1 或 0(TRUE 或 FALSE,例如 LIBXML_NOBLANKS(1))進(jìn)行設(shè)置。 可能的值:
|
data_is_url | 可選。如果是 TRUE 表明 data 是 XML 文檔的路徑或 URL,而不是字符串?dāng)?shù)據(jù)。默認(rèn)是 FALSE。 |
ns | 可選。規(guī)定命名空間前綴或 URI。 |
is_prefix | 可選。規(guī)定一個(gè)布爾值。如果 ns 是前綴則為 TRUE,如果 ns 是 URI 則為 FALSE。默認(rèn)是 FALSE。 |
技術(shù)細(xì)節(jié)
返回值: | 返回表示 data 的 SimpleXMLElement 對(duì)象。 |
---|---|
PHP 版本: | 5.0.1+ |
PHP 更新日志: | PHP 5.1.2:新增了 options 和 data_is_url 參數(shù)。 PHP 5.2:新增了 ns 和 is_prefix 參數(shù)。 |
更多實(shí)例
假設(shè)我們有如下的 XML 文件 note.xml :
<?xml version="1.0" encoding="UTF-8"?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
實(shí)例 1
從 URL 中創(chuàng)建一個(gè) SimpleXMLElement 對(duì)象:
<?php
$xml=new SimpleXMLElement("note.xml",0,TRUE);
echo $xml->asXML();
?>
運(yùn)行實(shí)例 ?
相關(guān)文章
- PHP 簡(jiǎn)介
- PHP 運(yùn)算符
- PHP Switch 語(yǔ)句
- PHP 數(shù)組排序
- PHP 發(fā)送電子郵件
- PHP 錯(cuò)誤處理
- PHP 異常處理
- PHP array_diff_ukey() 函數(shù)
- PHP array_key_exists() 函數(shù)
- PHP array_key_first() 函數(shù)
- PHP array_pop() 函數(shù)
- PHP array_rand() 函數(shù)
- PHP array_reduce() 函數(shù)
- PHP array_replace_recursive() 函數(shù)
- PHP array_splice() 函數(shù)
- PHP array_values() 函數(shù)
- PHP arsort() 函數(shù)
- PHP shuffle() 函數(shù)
- PHP cURL 函數(shù)
- PHP HTTP 函數(shù)