PHP simplexml_load_string() 函數
定義和用法
simplexml_load_string() 函數將 XML 字符串載入對象中。
如果失败,則返回 false。
语法定义
simplexml_load_file(string,class,options,ns,is_prefix)
ตัวแปร | คำอธิบาย |
---|---|
string | จำเป็น กำหนด XML ที่ใช้ |
class | เลือกตั้ง กำหนด class ของอนุประเภทใหม่ |
options | เลือกตั้ง กำหนดตัวแปร Libxml ติดตั้งเพิ่มเติม |
ns | เลือกตั้ง |
is_prefix | เลือกตั้ง |
กลับค่า
กลับค่าประมาณค่าของ SimpleXMLElement แบบอนุประเภท ซึ่งมีชนิดที่มีความหมายของข้อมูลในเอกสาร XML ถ้าล้มเหลวก็กลับค่า false
ตัวอย่าง
<?php $xmlstring = <<<XML <?xml version="1.0" encoding="ISO-8859-1"?> <note> <to>George</to> <from>John</from> <heading>Reminder</heading> <body>Don't forget the meeting!</body> </note> XML; $xml = simplexml_load_string($xmlstring); var_dump($xml); ?>
การแสดงผล:
object(SimpleXMLElement)#1 (4) { ["to"]=> string(4) "George" ["from"]=> string(4) "John" ["heading"]=> string(8) "Reminder" ["body"]=> string(29) "Don't forget the meeting!" }