PHP __construct() လုပ်ဆောင်ချက်
ဥပမာ
string တစ်ခုမှ SimpleXMLElement object တစ်ခုကို ဖန်တီးပါ-
<?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 အရာဝတ္ထုကို ပြန်ပေးသည်။ |
---|---|
PHP ဗားရှင်း- | 5.0+ |
PHP Changelog- | 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 အကိုးအကား