simplexml_load_file和simplexml_load_string之间的区别 [英] Difference between simplexml_load_file and simplexml_load_string
问题描述
我想将xml文件放入程序中并将其放入数组中,以便可以将其放入表中.
I want to put a xml file into my programme and make it into an array so I can put it into a table.
我想知道如何做到这一点,并且已经阅读了php手册,但是我似乎无法掌握它.
I was wondering how I can do this and I have read the php manual, but I don't seem to be able to get to grips with it.
要做我想做的事,我需要使用simplexml_load_string
,还是我需要命令它们两个(simplexml_load_file
和simplexml_load_string
),因此将xml文件加载到程序中,然后将其转换为一份文件.
或者simplesml_load_string
只是为我做所有这些事情.
To do what I want, do I need to use simplexml_load_string
, or do I need to command both of them(simplexml_load_file
and simplexml_load_string
), therefore load the xml file onto the programme, then turn it into a file.
Or does simplesml_load_string
just does all of that for me.
我还想知道get_object_vars
放在数组周围时会做什么.
Also I was wondering what get_object_vars
does when you put it around an array.
推荐答案
两个函数中的每个函数都返回SimpleXMLElement
对象,因此,根据您要开始的工作(是否有路径到一个对象),只需要其中的一个即可. XML文件或它本身的XML内容在字符串变量中,等等.
Each of the two functions returns SimpleXMLElement
object, so you only need one of them depending on what you have to begin with, whether you have path to an XML file or content of the XML it self in a string variable, etc.
在文档页面中的通知, simplexml_load_string()
期望string
参数包含实际的XML内容,而 simplexml_load_file()
期望string
参数包含XML文件的路径.
Notice in the documentation page, that simplexml_load_string()
expects the string
parameter to contain the actual XML content, while simplexml_load_file()
expects the string
parameter to contain path to the XML file.
这篇关于simplexml_load_file和simplexml_load_string之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!