如何在 PHP 中回顯 XML 檔案


HTTP URL 可以透過 PHP 包裝器像本地檔案一樣使用。可以使用 file_get_contents() 提取來自 URL 的內容,並且可以使用 readfile 函式回顯或讀取該內容。

下面是一個示例程式碼演示了這一點 −

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

下面演示了另一種方法 −

readfile('http://example.com/');
header('Content-type: text/xml'); //The correct MIME type has to be set before displaying the output.

也可以使用 asXML 方法。下面是一個示例程式碼 −

echo $xml->asXML();
or
$xml->asXML('filename.xml'); //providing a name for the xml file.

更新日期:07-4-2020

2K+ 瀏覽次數

開啟您的 職業生涯

完成課程,獲得認證

開始學習
廣告