PHP simplexml_load_file() လုပ်ဆောင်ချက်
ဥပမာ
XML ဖိုင်ကို အရာဝတ္ထုအဖြစ်သို့ ပြောင်းပါ၊ ထို့နောက် အရာဝတ္တု၏ သော့များနှင့် အစိတ်အပိုင်းများကို ထုတ်ပေးပါ-
<?php
$xml=simplexml_load_file("note.xml");
print_r($xml);
?>
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
simplexml_load_file() လုပ်ဆောင်ချက်သည် XML စာရွက်စာတမ်းကို အရာဝတ္ထုတစ်ခုအဖြစ်သို့ ပြောင်းပေးသည်။
အထားအသို
simplexml_load_file(file, class, options, ns, is_prefix)
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
file | Required. Specifies the path to the XML file |
class | Optional. Specifies the class of the new object |
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:
|
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 ဗားရှင်း- | ၅+ |
နောက်ထပ် ဥပမာများ
ကျွန်ုပ်တို့တွင် အောက်ပါ 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>
ဥပမာ
XML ဖိုင်တွင် ဒြပ်စင်တစ်ခုစီမှ ဒေတာကို ထုတ်ပါ-
<?php
$xml=simplexml_load_file("note.xml");
echo $xml->to . "<br>";
echo $xml->from . "<br>";
echo $xml->heading . "<br>";
echo $xml->body;
?>
ဥပမာ
XML ဖိုင်တွင် ကလေး node တစ်ခုစီအတွက် ဒြပ်စင်အမည်နှင့် ဒေတာကို ထုတ်ပေးသည်-
<?php
$xml=simplexml_load_file("note.xml");
echo $xml->getName() . "<br>";
foreach($xml->children() as $child)
{
echo $child->getName() . ": " . $child . "<br>";
}
?>
❮ PHP SimpleXML အကိုးအကား