PHP simplexml_load_file() Function
Complete PHP SimpleXML Reference
Definition and Usage
The simplexml_load_file() function loads an XML document into an object.
This function returns FALSE on
failure.
Syntax
|
simplexml_load_file(file,class,options,ns,is_prefix)
|
| Parameter |
Description |
| file |
Required. Specifies the XML document to use |
| 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:
- LIBXML_COMPACT - Set small nodes allocation optimization. This may
improve the application performance
- LIBXML_DTDATTR - Set default DTD attributes
- LIBXML_DTDLOAD - Load external subset
- LIBXML_DTDVALID - Validate with the DTD
- LIBXML_NOBLANKS - Remove blank nodes
- LIBXML_NOCDATA - Set CDATA as text nodes
- LIBXML_NOEMPTYTAG - Change empty tags (e.g. <br/> to <br></br>),
only available in the DOMDocument->save() and DOMDocument->saveXML()
functions
- LIBXML_NOENT - Substitute entities
- LIBXML_NOERROR - Do not show error reports
- LIBXML_NONET - Stop network access while loading documents
- LIBXML_NOWARNING - Do not show warning reports
- LIBXML_NOXMLDECL - Drop the XML declaration when saving a document
- LIBXML_NSCLEAN - Remove excess namespace declarations
- LIBXML_XINCLUDE - Use XInclude substitution
- LIBXML_ERR_ERROR - Get recoverable errors
- LIBXML_ERR_FATAL - Get fatal errors
- LIBXML_ERR_NONE - Get no errors
- LIBXML_ERR_WARNING - Get simple warnings
- LIBXML_VERSION - Get libxml version (e.g. 20605 or 20617)
- LIBXML_DOTTED_VERSION - Get dotted libxml version (e.g. 2.6.5 or
2.6.17)
|
| ns |
Optional |
| is_prefix |
Optional |
Example
XML File
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
|
PHP Code
<?php
if (file_exists('test.xml'))
{
$xml = simplexml_load_file('test.xml');
var_dump($xml);
}
else
{
exit('Error.');
}
?>
|
The output of the code above will be:
object(SimpleXMLElement)#1 (4)
{
["to"]=> string(4) "Tove"
["from"]=> string(4) "Jani"
["heading"]=> string(8) "Reminder"
["body"]=> string(29) "Don't forget me this weekend!"
}
|
Complete PHP SimpleXML Reference
Click here to design a Stunning Flash Website for Free
Wix is a revolutionary web design tool that provides anyone with the possibility to create professional and beautiful websites for free.
With e-commerce features, search engine visibility and many more professional tools, Wix is the ultimate solution for creating a spectacular site while saving tons of money.
 |
W3Schools' Online Certification Program
The perfect solution for professionals who need to balance work, family, and career building.
More than 4500 certificates already issued!
|
The HTML Certificate documents your knowledge of HTML, XHTML, and CSS.
The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.
The XML Certificate documents your knowledge of XML, XML DOM and XSLT.
The ASP Certificate documents your knowledge of ASP, SQL, and ADO.
The PHP Certificate documents your knowledge of PHP and SQL (MySQL).
|