PHP __construct () फ़ंक्शन
उदाहरण
एक स्ट्रिंग से SimpleXMLElement ऑब्जेक्ट बनाएं:
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Do not forget me this weekend!</body>
</note>
XML;
$xml=new SimpleXMLElement($note);
echo $xml->asXML();
?>
परिभाषा और उपयोग
__construct() फ़ंक्शन एक नया SimpleXMLElement ऑब्जेक्ट बनाता है।
वाक्य - विन्यास
SimpleXMLElement::__construct(data, options, data_is_url, ns, is_prefix)
पैरामीटर मान
Parameter | Description |
---|---|
data | Required. Specifies A well-formed XML string or the path or URL to an XML document if data_is_url is TRUE |
options | Optional. Specifies additional Libxml parameters. Is set by specifying the option and 1 or 0 (TRUE or FALSE, e.g. LIBXML_NOBLANKS(1)) Possible values:
|
data_is_url | Optional. TRUE specifies that data is a path/URL to an XML document instead of string data. Default is FALSE |
ns | Optional. Specifies a namespace prefix or URI |
is_prefix | Optional. Specifies a Boolean value. TRUE if ns is a prefix. FALSE if ns is a URI. Default is FALSE |
टेक्निकल डिटेल
प्रतिलाभ की मात्रा: | एक SimpleXMLElement ऑब्जेक्ट देता है जो डेटा का प्रतिनिधित्व करता है |
---|---|
पीएचपी संस्करण: | 5.0+ |
पीएचपी चेंजलॉग: | PHP 5.2.0: वैकल्पिक ns और is_prefix पैरामीटर जोड़े गए। PHP 5.1.2: वैकल्पिक विकल्प और data_is_url पैरामीटर जोड़े गए। |
और ज्यादा उदाहरण
मान लें कि हमारे पास निम्न 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>
उदाहरण
URL से SimpleXMLElement ऑब्जेक्ट बनाएं:
<?php
$xml=new SimpleXMLElement("note.xml", 0, TRUE);
echo $xml->asXML();
?>
❮ PHP SimpleXML संदर्भ