首頁  >  文章  >  後端開發  >  如何在PHP中輸出XML文件

如何在PHP中輸出XML文件

WBOY
WBOY轉載
2023-09-03 17:45:12848瀏覽

如何在PHP中輸出XML文件

在 PHP 包裝器的幫助下,HTTP URL 的行為可以像本機檔案一樣。可以透過 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.

以上是如何在PHP中輸出XML文件的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除