PHP simplexml_load_file() ফাংশন
বিন্যাস ও ব্যবহার
simplexml_load_file() ফাংশন XML ডকুমেন্টকে অবজেক্টে লোড করে।
যদি ব্যর্থ হোক, তবে false ফিরিয়ে দিয়েছে।
বিন্যাস
simplexml_load_file(file,class,options,ns,is_prefix)
প্রমাণপত্র | বর্ণনা |
---|---|
file | Required. Specifies the XML document to be used. |
class | Optional. Specifies the class of the new object. |
options | Optional. Specifies additional Libxml parameters. |
ns | Optional. |
is_prefix | Optional. |
Return Value
Returns an object of class SimpleXMLElement, whose properties contain the data from the XML document. If it fails, it returns false.
Example
XML File:
<?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>
PHP Code:
<?php if (file_exists('test.xml')) { $xml = simplexml_load_file('test.xml'); var_dump($xml); } else { exit('Error.'); } ?>
Output:
object(SimpleXMLElement)#1 (4) { ["to"]=> string(4) "George" ["from"]=> string(4) "John" ["heading"]=> string(8) "Reminder" ["body"]=> string(29) "Don't forget the meeting!" }