English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP simplexml_load_file() Function Usage and Example

PHP SimpleXML Function Manual

The simplexml_load_file() function is used to convert a simple xml file to a SimpleXMLElement object.

Syntax

simplexml_load_file(file,classname,options,ns,is_prefix);

Definition and Usage

It is used to convert a simple xml file to a SimpleXMLElement object.

Return Value

Returns a SimpleXMLElement object if successful, returns false if failed

Parameter

Serial NumberParameters and Description
1

file

Specify the path of the xml file

2

classname

Specify the class of the new object

3

ns

Specify namespace prefix or URI

4

is_prefix

If ns is a prefix, then TRUE; if it is a URI, then FALSE; the default value is FALSE.

Online Example

Try the following example, convert XML file to SimpleXMLElement object and then output the keys and values of the object:

<?php
   //Convert XML file to SimpleXMLElement object and then output the keys and values of the object
   $xml = simplexml_load_file("sample.xml");
   print_r($xml);
?>
Test and see‹/›

Output Result

SimpleXMLElement Object ([to] => gopal [from] => CEO [heading] => Reminder [body] => Don't forget to send a file to me )

PHP SimpleXML Function Manual