Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何解决这个simplexml\u加载\u文件问题_Php_Xml - Fatal编程技术网

Php 如何解决这个simplexml\u加载\u文件问题

Php 如何解决这个simplexml\u加载\u文件问题,php,xml,Php,Xml,我试图通过使用simplexml\u load\u文件将xml转换为xml对象。然而,我有一个错误,说 PHP Warning: simplexml_load_file() expects parameter 1 to be string, array given in ....... line 50 我正在尝试使用的xml文件 不知道怎么做。谢谢你的帮助 它通过以下方式对我有效: $raw = "http://api.wolframalpha.com/v1/query.jsp?appid=

我试图通过使用simplexml\u load\u文件将xml转换为xml对象。然而,我有一个错误,说

PHP Warning: simplexml_load_file() expects parameter 1 to be string, array given in  ....... line 50
我正在尝试使用的xml文件


不知道怎么做。谢谢你的帮助

它通过以下方式对我有效:

$raw = "http://api.wolframalpha.com/v1/query.jsp?appid=GJUJH5-8RJR4ELL82&input=pi";
$xml = simplexml_load_file($raw);

echo '<pre>';
print_r($xml);
echo '</pre>';
这反映了:

$fileContents = file_get_contents("./stuff.xml");
$stringXml = simplexml_load_string($fileContents);

$remoteXml = simplexml_load_file("http://api.wolframalpha.com/v1/query.jsp?appid=GJUJH5-8RJR4ELL82&input=pi");
$localXml = simplexml_load_file("./stuff.xml");
希望这有帮助

像这样使用它。第一个是将解析后的内容加载到字符串中,然后使用simplexml\u load\u字符串进行转换


后两个示例显示您可以从本地或远程源访问它,但函数simplexml\u load\u file需要一个文件位置作为源。

您的目的是传递字符串而不是数组。您的代码给出语法错误:解析错误:语法错误,意外的T\u字符串打开。。。。请仅发布代码示例来演示您的问题!您是否尝试读取错误消息?我认为他实际上是将xml内容复制到$response中,而不是复制到它的url中。如果可以的话
foreach ($xml->pod as $pod)
{
    echo $pod->attributes()->title.'<br>';
}
Input
Decimal approximation
Property
Number line
Continued fraction
Alternative representations
Series representations
Integral representations
$fileContents = file_get_contents("./stuff.xml");
$stringXml = simplexml_load_string($fileContents);

$remoteXml = simplexml_load_file("http://api.wolframalpha.com/v1/query.jsp?appid=GJUJH5-8RJR4ELL82&input=pi");
$localXml = simplexml_load_file("./stuff.xml");