دالة 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 يمثل البيانات |
---|---|
إصدار PHP: | 5.0+ |
سجل التغيير في PHP: | 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>
مثال
قم بإنشاء كائن SimpleXMLElement من عنوان URL:
<?php
$xml=new SimpleXMLElement("note.xml", 0, TRUE);
echo $xml->asXML();
?>
❮ مرجع PHP SimpleXML