Skip to content
Related Articles

Related Articles

Improve Article

PHP | DOMNode lookupNamespaceUri() Function

  • Last Updated : 02 Mar, 2020

The DOMNode::lookupNamespaceUri() function is an inbuilt function in PHP which is used to get the namespace URI of the node based on the prefix.


string DOMNode::lookupNamespaceUri( string $prefix )

Parameters: This function accepts a single parameter $prefix which holds the prefix.

Return Value: This function returns namespace URI of the node.

Below examples illustrate the DOMNode::lookupNamespaceUri() function in PHP:

Example 1:

// Create a new DOMDocument instance
$document = new DOMDocument();
// Create a XML variable with no namespace
$xml = <<<XML
<?xml version="1.0" encoding="utf-8"?>
// Load the XML
// Get the default namespace URI
$uri = $document->documentElement->lookupnamespaceURI(null);
echo $uri;


// Empty string which means no namespace is there.

Example 2:

// Create a new DOMDocument instance
$document = new DOMDocument();
// Load the XML with a namespace with prefix x
$document->loadXML("<?xml version=\"1.0\"?>
    <div xmlns:x=\"my_namespace\">
        <x:h1 x:style=\"color:red;\"> GeeksforGeeks </x:h1>
// Get the URI with prefix x
$uri = $document->documentElement->lookupnamespaceURI('x');
echo $uri;




My Personal Notes arrow_drop_up
Recommended Articles
Page :