Php simplexml_加载带有变量的文件()
我当前在simplexml_load_file()方面遇到问题;我的xml路径是一个url,它作为变量呈现Php simplexml_加载带有变量的文件(),php,xml,simplexml,Php,Xml,Simplexml,我当前在simplexml_load_file()方面遇到问题;我的xml路径是一个url,它作为变量呈现 $xurl = "domain/pathto/myfile.xml"; // This is actually a variable that returns the entire URL to where my xml file is -- this will change from file to file $xmlpath = parse_url($xurl, PHP_URL_
$xurl = "domain/pathto/myfile.xml"; // This is actually a variable that returns the entire URL to where my xml file is -- this will change from file to file
$xmlpath = parse_url($xurl, PHP_URL_PATH); // to get the path of my xml file ex. /pathto/myfile.xml
$xmlpath = mb_substr($xmlpath, 1); // returns pathto/myfile.xml
这就是我的问题所在,当我把它放到:
simplexml_load_file($xmlpath);
在我的函数中,XML文件中没有显示任何内容
但是,如果我将其更改为
simplexml_load_file("pathto/myfile.xml");
我的功能正常
我在$xmlpath上做了一个echo,它将路径返回到/myfile.xml
<?php echo $xmlpath; ?> // returns pathto/myfile.xml
返回0。是否完全确定路径相同
echo strcmp(“pathto/myfile.xml”,$xmlpath)
。此外,您应该在开发时在php.ini
文件中启用display_errors
并将error_reporting
设置为E_ALL
simplexml\u load\u file
应该会触发一个警告,如果它失败了,使用该代码,我将返回一个0。很遗憾,我无法控制php.ini。好吧,0
表示它们是相同的。将其放在脚本顶部(但在完成开发后将其删除)<代码>ini设置(“显示错误”,“打开”);错误报告(E_全部)代码>快速搜索表明错误通常意味着文件不存在于指定的路径。尝试使用当前脚本的目录作为路径的前缀,例如simplexml\u load\u file(\uuuu DIR\uuu.$xmlpath)
(假设XML文件与PHP脚本相关)忘记添加,如果前缀为\uu DIR\uu
,请不要去掉前导正斜杠
echo strcmp("pathto/myfile.xml", $xmlpath)