PHP | XMLReader close() Function

The XMLReader::close() function is an inbuilt function in PHP which is used to close the input of XMLReader object which is currently parsing.
Syntax:
bool XMLReader::close( void )
Parameters: This function doesn’t accepts any parameters.
Return Value: This function returns TRUE on success or FALSE on failure.
Below examples illustrate the XMLReader::close() function in PHP:
Program 1:
- data.xml
<?xmlversion="1.0"encoding="utf-8"?><root><p> Hello world </p></root> - index.php
<?php// Create a new XMLReader instance$XMLReader=newXMLReader();// 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 browserecho$string;?> - Output:
// Blank because we closed the input of the XMLReader before reading XML
Program 2:
- data.xml
<?xmlversion="1.0"encoding="utf-8"?><body><h1> zambiatek </h1></body> - index.php
<?php// Create a new XMLReader instance$XMLReader=newXMLReader();// 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 browserecho$string;// Close the XML Reader after reading XML$XMLReader->close();?> - Output:
zambiatek
Reference: https://www.php.net/manual/en/xmlreader.close.php



