DOMNode::lookupNamespaceUri()函數是PHP中的內置函數,用於根據前綴獲取節點的名稱空間URI。
用法:
string DOMNode::lookupNamespaceUri( string $prefix )
參數:該函數接受一個包含前綴的單個參數$prefix。
返回值:此函數返回節點的名稱空間URI。
以下示例說明了PHP中的DOMNode::lookupNamespaceUri()函數:
範例1:
<?php
// Create a new DOMDocument instance
$document = new DOMDocument();
// Create a XML variable with no namespace
$xml = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<root>
<h1>GeeksforGeeks</h1>
</root>
XML;
// Load the XML
$document->loadXML($xml);
// Get the default namespace URI
$uri = $document->documentElement->lookupnamespaceURI(null);
echo $uri;
?>
輸出:
// Empty string which means no namespace is there.
範例2:
<?php
// 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>
</div>
");
// Get the URI with prefix x
$uri = $document->documentElement->lookupnamespaceURI('x');
echo $uri;
?>
輸出:
my_namespace
參考: https://www.php.net/manual/en/domnode.lookupnamespaceuri.php
相關用法
- PHP DOMNode C14NFile()用法及代碼示例
- PHP DOMNode C14N()用法及代碼示例
- PHP DOMNode getNodePath()用法及代碼示例
- PHP DOMNode lookupPrefix()用法及代碼示例
- PHP DOMNode cloneNode()用法及代碼示例
- PHP DOMNode removeChild()用法及代碼示例
- PHP DOMNode normalize()用法及代碼示例
- PHP DOMNode isDefaultNamespace()用法及代碼示例
- PHP DOMNode hasAttributes()用法及代碼示例
- PHP DOMNode hasChildNodes()用法及代碼示例
- PHP DOMNode isSupported()用法及代碼示例
- PHP DOMNode appendChild()用法及代碼示例
- PHP DOMNode getLineNo()用法及代碼示例
注:本文由純淨天空篩選整理自gurrrung大神的英文原創作品 PHP | DOMNode lookupNamespaceUri() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。