PHP simplexml_load_file() º¯Êý
¶¨ÒåºÍÓ÷¨
simplexml_load_file() º¯Êý°Ñ XML ÎĵµÔØÈë¶ÔÏóÖС£
Èç¹ûʧ°Ü£¬Ôò·µ»Ø false¡£
Óï·¨
simplexml_load_file(file,class,options,ns,is_prefix)
| ²ÎÊý | ÃèÊö |
|---|---|
| file | ±ØÐè¡£¹æ¶¨ÒªÊ¹ÓÃµÄ XML Îĵµ¡£ |
| class | ¿ÉÑ¡¡£¹æ¶¨Ð¶ÔÏóµÄ class¡£ |
| options | ¿ÉÑ¡¡£¹æ¶¨¸½¼ÓµÄ Libxml ²ÎÊý¡£ |
| ns | ¿ÉÑ¡¡£ |
| is_prefix | ¿ÉÑ¡¡£ |
·µ»ØÖµ
·µ»ØÀà SimpleXMLElement µÄÒ»¸ö¶ÔÏ󣬸öÔÏóµÄÊôÐÔ°üº¬ XML ÎĵµÖеÄÊý¾Ý¡£Èç¹ûʧ°Ü£¬Ôò·µ»Ø false¡£
Àý×Ó
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>
PHP ´úÂ룺
<?php
if (file_exists('test.xml'))
{
$xml = simplexml_load_file('test.xml');
var_dump($xml);
}
else
{
exit('Error.');
}
?>
Êä³ö£º
object(SimpleXMLElement)#1 (4)
{
["to"]=> string(4) "George"
["from"]=> string(4) "John"
["heading"]=> string(8) "Reminder"
["body"]=> string(29) "Don't forget the meeting!"
}