How to echo xml file in php

前端 未结 10 913
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-29 04:37

How to print an xml file to the screen in php?

This is not working:

$curl = curl_init();        
curl_setopt ($curl, CURLOPT_URL, \'http://rss.news.y         


        
10条回答
  •  不知归路
    2020-11-29 04:53

    You can use HTTP URLs as if they were local files, thanks to PHP's wrappers

    You can get the contents from an URL via file_get_contents() and then echo it, or even read it directly using readfile()

    $file = file_get_contents('http://example.com/rss');
    echo $file;
    

    or

    readfile('http://example.com/rss');
    

    Don't forget to set the correct MIME type before outputing anything, though.

    header('Content-type: text/xml');
    

提交回复
热议问题