在我的脚本中,我正在从网上下载一个 XML 文件并打印它的内容。问题是它在浏览器中没有打印内容,但是在使用时在终端中却成功了
php index.php
当我使用时还有一件事:
<?php $x = file_get_contents("127.0.0.1/x.xml"); var_dump($x); ?>
它成功地在浏览器中打印了 xml 的内容,但如果我使用:
<?php $x = file_get_contents($ncbi_web_address."ncbi.xml"); var_dump($x); ?>
它不会在浏览器中打印内容,但会在终端中成功打印内容。
编辑:不工作,如果代码有帮助:
<?php header("Content-Type:text/plain");
search($query);
function search($query){
$url = "http://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/name/".$query."/XML";
//$url = "http://127.0.0.1/x.xml"; (This one working)
$xml = file_get_contents($url);
var_dump($xml);
}
?>