PHP __construct() 函數(shù)
定義和用法
__construct() 函數(shù)創(chuàng)建一個新的 SimpleXMLElement 對象。
如果成功,則該函數(shù)返回一個對象。如果失敗,則返回 false。
語法
__construct(data,options,is_url,ns,is_prefix)
參數(shù) | 描述 |
---|---|
data | 必需。形式良好的 XML 字符串或 XML 文檔的路徑或 URL。 |
options | 可選。規(guī)定附加的 Libxml 參數(shù)。 |
is_url | 可選。規(guī)定 data 參數(shù)是否是 URL。默認是 false。 |
ns | 可選。 |
is_prefix | 可選。 |
返回值
返回一個表示數(shù)據(jù)的 SimpleXMLElement 對象。
例子
<?php
$xmlstring = <<<XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
</note>
XML;
$xml = new SimpleXMLElement($xmlstring)
;
echo $xml->body[0];
?>
輸出類似:
Don't forget the meeting!