XMLReader::close()函數是PHP中的一個內置函數,用於關閉當前正在解析的XMLReader對象的輸入。
用法:
bool XMLReader::close( void )
參數:此函數不接受任何參數。
返回值:如果成功,此函數將返回TRUE,否則將返回FALSE。
以下示例說明了PHP中的XMLReader::close()函數:
程序1:
- data.xml
<?xml version="1.0" encoding="utf-8"?> <root> <p> Hello world </p> </root>
- index.php
<?php // Create a new XMLReader instance $XMLReader = new XMLReader(); // Open the XML file $XMLReader->open('data.xml'); // Close the XML Reader before reading XML $XMLReader->close(); // Move to the first node $XMLReader->read(); // Read it as a string $string = $XMLReader->readString(); // Output the string to the browser echo $string; ?>
- 輸出:
// Blank because we closed the input of the XMLReader before reading XML
程序2:
- data.xml
<?xml version="1.0" encoding="utf-8"?> <body> <h1> GeeksforGeeks </h1> </body>
- index.php
<?php // Create a new XMLReader instance $XMLReader = new XMLReader(); // Open the XML file $XMLReader->open('data.xml'); // Move to the first node $XMLReader->read(); // Read it as a string $string = $XMLReader->readString(); // Output the string to the browser echo $string; // Close the XML Reader after reading XML $XMLReader->close(); ?>
- 輸出:
GeeksforGeeks
參考: https://www.php.net/manual/en/xmlreader.close.php
相關用法
- PHP XMLReader XML()用法及代碼示例
- PHP XMLReader open()用法及代碼示例
- PHP XMLReader getParserProperty()用法及代碼示例
- PHP XMLReader getAttributeNs()用法及代碼示例
- PHP XMLReader readInnerXml()用法及代碼示例
- PHP XMLReader setSchema()用法及代碼示例
- PHP XMLReader setRelaxNGSchemaSource()用法及代碼示例
- PHP XMLReader setRelaxNGSchema()用法及代碼示例
- PHP XMLReader setParserProperty()用法及代碼示例
- PHP XMLReader readString()用法及代碼示例
- PHP XMLReader readOuterXml()用法及代碼示例
- PHP XMLReader moveToNextAttribute()用法及代碼示例
- PHP XMLReader moveToFirstAttribute()用法及代碼示例
- PHP Spreadsheet_Excel_Writer Close()用法及代碼示例
- HTML DOM close()用法及代碼示例
注:本文由純淨天空篩選整理自gurrrung大神的英文原創作品 PHP | XMLReader close() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。