PHP | DOMNode lookupPrefix() Function
Last Updated :
30 Nov, 2021
The DOMNode::lookupPrefix() function is an inbuilt function in PHP which is used to get the namespace prefix of the node based on the namespace URI.
Syntax:
string DOMNode::lookupPrefix( string $namespaceURI )
Parameters: This function accepts a single parameter $namespaceURI which holds the namespace URI.
Return Value: This function returns the prefix of the namespace.
Below examples illustrate the DOMNode::lookupPrefix() function in PHP:
Example 1:
php
<?php
$document = new DOMDocument();
$document ->loadXML("<?xml version=\"1.0\"?>
<div >
<h1> GeeksforGeeks </h1>
</div>
");
$prefix = $document ->documentElement->
lookupPrefix( "my_nsamespace" );
echo $prefix ;
?>
|
Output:
// Empty string as there is no such namespace
Example 2:
php
<?php
$document = new DOMDocument();
$document ->loadXML("<?xml version=\"1.0\"?>
<div xmlns:x=\"my_namespace\">
<x:h1 x:style=\"color:red;\">
GeeksforGeeks
</x:h1>
</div>
");
$prefix = $document ->documentElement->
lookupPrefix( 'my_namespace' );
echo $prefix ;
?>
|
Output:
x
Reference: https://www.php.net/manual/en/domnode.lookupprefix.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...