PHP | XMLReader moveToFirstAttribute() Function
Last Updated :
18 Mar, 2020
The XMLReader::moveToFirstAttribute() function is an inbuilt function in PHP which is used to position cursor on the first attribute of the element. This function is useful when we have multiple attributes for an element and we want to get the first one or when we want to check if an element has any attributes or not.
Syntax:
bool XMLReader::moveToFirstAttribute( void )
Parameters: This function doesn’t accept any parameter.
Return Value: This function returns TRUE on success or FALSE on failure.
Below examples illustrate the XMLReader::moveToFirstAttribute() function in PHP:
Example 1:
- data.xml
<? xml version = "1.0" encoding = "utf-8" ?>
< div >
< h1 >Foo Bar</ h1 >
</ div >
|
- index.php
<?php
$XMLReader = new XMLReader();
$XMLReader ->open( 'data.xml' );
$XMLReader ->read();
$XMLReader ->read();
$XMLReader ->read();
if ( $XMLReader ->moveToFirstAttribute()) {
echo "Attribute is there" ;
} else {
echo "No, attributes." ;
}
?>
|
- Output:
No, attributes.
Program 2:
Reference: https://www.php.net/manual/en/xmlreader.movetofirstattribute.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...