我正在使用SimpleXML从xml文件将数据导入php数组.
我正在使用该simplexml_load_file功能,但是一旦我得到了我需要的数据,我是否需要关闭文件或类似的以清除内存?
谢谢,
詹姆士
不,你不需要对文件做任何事情.simplexml_load_file()在读取内容后将在内部关闭文件.
如果您查看源代码simplexml_load_file,您将看到它正在调用C函数xmlReadFile()形式xmllib2,而后者将在读取后关闭该文件.
PHP_FUNCTION(simplexml_load_file)
{
php_sxe_object *sxe;
char *filename;
int filename_len;
xmlDocPtr docp;
char *ns = NULL;
int ns_len = 0;
long options = 0;
zend_class_entry *ce= sxe_class_entry;
zend_bool isprefix = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|C!lsb", &filename, &filename_len, &ce, &options, &ns, &ns_len, &isprefix) == FAILURE) {
return;
}
docp = xmlReadFile(filename, NULL, options); <--- reading the file
Run Code Online (Sandbox Code Playgroud)