PHP simplexml_load_file() İşlevi
Örnek
Bir XML dosyasını bir nesneye dönüştürün, ardından nesnenin anahtarlarını ve öğelerini çıktılayın:
<?php
$xml=simplexml_load_file("note.xml");
print_r($xml);
?>
Tanım ve Kullanım
simplexml_load_file() işlevi, bir XML belgesini bir nesneye dönüştürür.
Sözdizimi
simplexml_load_file(file, class, options, ns, is_prefix)
Parametre Değerleri
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 |
Teknik detaylar
Geri dönüş değeri: | Başarılı bir SimpleXMLElement nesnesi. Başarısızlıkta YANLIŞ |
---|---|
PHP Sürümü: | 5+ |
Daha fazla örnek
Aşağıdaki XML dosyamız olduğunu varsayalım, " 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>
Örnek
XML dosyasındaki her bir öğeden veri çıktısı alın:
<?php
$xml=simplexml_load_file("note.xml");
echo $xml->to . "<br>";
echo $xml->from . "<br>";
echo $xml->heading . "<br>";
echo $xml->body;
?>
Örnek
XML dosyasındaki her bir alt düğüm için öğenin adını ve verilerini çıktılayın:
<?php
$xml=simplexml_load_file("note.xml");
echo $xml->getName() . "<br>";
foreach($xml->children() as $child)
{
echo $child->getName() . ": " . $child . "<br>";
}
?>
❮ PHP SimpleXML Referansı