In my script I'm downloading a XML file from the web and printing it's content. The problem is that it does not print the content in the browser, but it does successfully in the terminal when using
在我的脚本中,我从web下载一个XML文件并打印它的内容。问题是它不会在浏览器中打印内容,但是在使用时它会成功地在终端上打印。
php index.php
One more thing when I use:
当我使用的时候还有一件事:
<?php $x = file_get_contents("127.0.0.1/x.xml"); var_dump($x); ?>
It successfully print the content of the xml in the browser but if i use:
它成功地在浏览器中打印xml的内容,但是如果我使用:
<?php $x = file_get_contents($ncbi_web_address."ncbi.xml"); var_dump($x); ?>
It does not print the content in the browser but prints content successfully in the teminal.
它不会在浏览器中打印内容,而是在teminal中成功地打印内容。
EDIT: Not working, If code helps:
编辑:不工作,如果代码有帮助:
<?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);
}
?>
1 个解决方案
#1
5
Since you are sending an HTML document to the browser, the XML tags will be treated as unrecognized HTML tags and ignored.
由于您正在向浏览器发送HTML文档,因此XML标记将被视为不可识别的HTML标记并被忽略。
Add
添加
header("Content-Type: text/plain")
to the top of the PHP program.
到PHP程序的顶部。
#1
5
Since you are sending an HTML document to the browser, the XML tags will be treated as unrecognized HTML tags and ignored.
由于您正在向浏览器发送HTML文档,因此XML标记将被视为不可识别的HTML标记并被忽略。
Add
添加
header("Content-Type: text/plain")
to the top of the PHP program.
到PHP程序的顶部。