XMLWriter::openUri()函數是PHP中的內置函數,可用於使用源URI創建新的XMLWriter,以進行輸出。簡而言之,此函數決定了如何通過瀏覽器或直接將XML輸出給用戶。
用法:
bool XMLWriter::openUri( string $uri )
參數:該函數接受單個參數$uri,該參數保存uri用於輸出。
返回值:如果成功,此函數將返回TRUE,否則將返回FALSE。
以下示例說明了PHP中的XMLWriter::openUri()函數:
範例1:
<?php
// Create a new XMLWriter instance
$writer = new XMLWriter();
// Create the output stream as PHP
$writer->openURI('php://output');
// Start the document
$writer->startDocument('1.0', 'UTF-8');
// Start a element
$writer->startElement('i');
// Add value to the element
$writer->text('GeeksforGeeks');
// End the element
$writer->endElement();
// End the document
$writer->endDocument();
?>
輸出:
GeeksforGeeks
範例2:
<?php
// Create a new XMLWriter instance
$writer = new XMLWriter();
// Create the output stream to a file
$writer->openURI('new.xml');
// Start the document
$writer->startDocument('1.0', 'UTF-8');
// Start a element
$writer->startElement('div');
// Add value to the element
$writer->text('Hello World');
// End the element
$writer->endElement();
// End the document
$writer->endDocument();
?>
輸出:這將在具有以下內容的同一文件夾中創建一個名為new.xml的新文件。
參考: https://www.php.net/manual/en/function.xmlwriter-open-uri.php
相關用法
- PHP XMLWriter startDocument()用法及代碼示例
- PHP XMLWriter startComment()用法及代碼示例
- PHP XMLWriter startCdata()用法及代碼示例
- PHP XMLWriter endElement()用法及代碼示例
- PHP XMLWriter setIndent()用法及代碼示例
- PHP XMLWriter fullEndElement()用法及代碼示例
- PHP XMLWriter startAttributeNs()用法及代碼示例
- PHP XMLWriter endPi()用法及代碼示例
- PHP XMLWriter startAttribute()用法及代碼示例
- PHP XMLWriter endComment()用法及代碼示例
- PHP XMLWriter endDtdEntity()用法及代碼示例
- PHP XMLWriter startDtdAttlist()用法及代碼示例
- PHP XMLWriter endDocument()用法及代碼示例
- PHP XMLWriter endCdata()用法及代碼示例
- PHP XMLWriter endAttribute()用法及代碼示例
注:本文由純淨天空篩選整理自gurrrung大神的英文原創作品 PHP | XMLWriter openUri() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。