<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.domxpath.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'domxpath.registerphpfunctionns.php',
    1 => 'DOMXPath::registerPhpFunctionNS',
    2 => 'Register a PHP functions as namespaced XPath function',
  ),
  'up' => 
  array (
    0 => 'class.domxpath.php',
    1 => 'DOMXPath',
  ),
  'prev' => 
  array (
    0 => 'domxpath.registernamespace.php',
    1 => 'DOMXPath::registerNamespace',
  ),
  'next' => 
  array (
    0 => 'domxpath.registerphpfunctions.php',
    1 => 'DOMXPath::registerPhpFunctions',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/dom/domxpath/registerphpfunctionns.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="domxpath.registerphpfunctionns" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">DOMXPath::registerPhpFunctionNS</h1>
  <p class="verinfo">(PHP &gt;= 8.4.0)</p><p class="refpurpose"><span class="refname">DOMXPath::registerPhpFunctionNS</span> &mdash; <span class="dc-title">Register a PHP functions as namespaced XPath function</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-domxpath.registerphpfunctionns-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>DOMXPath::registerPhpFunctionNS</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$namespaceURI</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$name</code></span>, <span class="methodparam"><span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span> <code class="parameter">$callable</code></span>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>

  <p class="simpara">
   This method enables the ability to use a PHP function as a namespaced XPath function
   inside XPath expressions.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-domxpath.registerphpfunctionns-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt><code class="parameter">namespaceURI</code></dt>
    <dd>
     <span class="simpara">
      The URI of the namespace.
     </span>
    </dd>
   
   
    <dt><code class="parameter">name</code></dt>
    <dd>
     <span class="simpara">
      The local function name inside the namespace.
     </span>
    </dd>
   
   
    <dt><code class="parameter">callable</code></dt>
    <dd>
     <span class="simpara">
      The PHP function to call when the XPath function gets called within the XPath expression.
      When a node list is passed as parameter to the callback,
      they are arrays containing the matched DOM nodes.
     </span>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 errors" id="domxpath.registerphpfunctions..errors">
  <h3 class="title">错误／异常</h3>
  <ul class="itemizedlist">
   <li class="listitem">
    <span class="simpara">
     Throws a <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span> if
     a callback name is not valid.
    </span>
   </li>
   <li class="listitem">
 <span class="simpara">
  Throws a <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span> if
  <code class="parameter">options</code> contains an invalid option.
 </span>
</li>
<li class="listitem">
 <span class="simpara">
  Throws a <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span> if
  <code class="parameter">overrideEncoding</code> is an unknown encoding.
 </span>
</li>
   <li class="listitem">
    <span class="simpara">
     Throws a <span class="exceptionname"><a href="class.typeerror.php" class="exceptionname">TypeError</a></span> if
     a given callback is not callable.
    </span>
   </li>
  </ul>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-domxpath.registerphpfunctionns-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="simpara">
   没有返回值。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-domxpath.registerphpfunctionns-examples">
  <h3 class="title">示例</h3>
  <div class="example" id="example-1">
   <p><strong>示例 #1 Register a namespaced XPath function and call it from the XPath expression</strong></p>
   <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$xml </span><span style="color: #007700">= &lt;&lt;&lt;EOB<br /></span><span style="color: #DD0000">&lt;books&gt;<br />&lt;book&gt;<br /> &lt;title&gt;PHP Basics&lt;/title&gt;<br /> &lt;author&gt;Jim Smith&lt;/author&gt;<br /> &lt;author&gt;Jane Smith&lt;/author&gt;<br />&lt;/book&gt;<br />&lt;book&gt;<br /> &lt;title&gt;PHP Secrets&lt;/title&gt;<br /> &lt;author&gt;Jenny Smythe&lt;/author&gt;<br />&lt;/book&gt;<br />&lt;book&gt;<br /> &lt;title&gt;XML basics&lt;/title&gt;<br /> &lt;author&gt;Joe Black&lt;/author&gt;<br />&lt;/book&gt;<br />&lt;/books&gt;<br /></span><span style="color: #007700">EOB;<br /><br /></span><span style="color: #0000BB">$doc </span><span style="color: #007700">= new </span><span style="color: #0000BB">DOMDocument</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">loadXML</span><span style="color: #007700">(</span><span style="color: #0000BB">$xml</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$xpath </span><span style="color: #007700">= new </span><span style="color: #0000BB">DOMXPath</span><span style="color: #007700">(</span><span style="color: #0000BB">$doc</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Register the my: namespace (required)<br /></span><span style="color: #0000BB">$xpath</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">registerNamespace</span><span style="color: #007700">(</span><span style="color: #DD0000">"my"</span><span style="color: #007700">, </span><span style="color: #DD0000">"urn:my.ns"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Register PHP function<br /></span><span style="color: #0000BB">$xpath</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">registerPHPFunctionNS</span><span style="color: #007700">(<br />    </span><span style="color: #DD0000">'urn:my.ns'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'substring'</span><span style="color: #007700">,<br />    fn (array </span><span style="color: #0000BB">$arg1</span><span style="color: #007700">, </span><span style="color: #0000BB">int $start</span><span style="color: #007700">, </span><span style="color: #0000BB">int $length</span><span style="color: #007700">) =&gt; </span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">$arg1</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]-&gt;</span><span style="color: #0000BB">textContent</span><span style="color: #007700">, </span><span style="color: #0000BB">$start</span><span style="color: #007700">, </span><span style="color: #0000BB">$length</span><span style="color: #007700">)<br />);<br /><br /></span><span style="color: #FF8000">// Call substr function on the book title<br /></span><span style="color: #0000BB">$nodes </span><span style="color: #007700">= </span><span style="color: #0000BB">$xpath</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">'//book[my:substring(title, 0, 3) = "PHP"]'</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #DD0000">"Found </span><span style="color: #007700">{</span><span style="color: #0000BB">$nodes</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">length</span><span style="color: #007700">}</span><span style="color: #DD0000"> books starting with 'PHP':\n"</span><span style="color: #007700">;<br />foreach (</span><span style="color: #0000BB">$nodes </span><span style="color: #007700">as </span><span style="color: #0000BB">$node</span><span style="color: #007700">) {<br />   </span><span style="color: #0000BB">$title  </span><span style="color: #007700">= </span><span style="color: #0000BB">$node</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getElementsByTagName</span><span style="color: #007700">(</span><span style="color: #DD0000">"title"</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">item</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">nodeValue</span><span style="color: #007700">;<br />   </span><span style="color: #0000BB">$author </span><span style="color: #007700">= </span><span style="color: #0000BB">$node</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getElementsByTagName</span><span style="color: #007700">(</span><span style="color: #DD0000">"author"</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">item</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">nodeValue</span><span style="color: #007700">;<br />   echo </span><span style="color: #DD0000">"</span><span style="color: #0000BB">$title</span><span style="color: #DD0000"> by </span><span style="color: #0000BB">$author</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>以上示例的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">Found 2 books starting with &#039;PHP&#039;:
PHP Basics by Jim Smith
PHP Secrets by Jenny Smythe</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-domxpath.registerphpfunctionns-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li><span class="methodname"><a href="domxpath.registernamespace.php" class="methodname" rel="rdfs-seeAlso">DOMXPath::registerNamespace()</a> - Registers the namespace with the DOMXPath object</span></li>
   <li><span class="methodname"><a href="domxpath.query.php" class="methodname" rel="rdfs-seeAlso">DOMXPath::query()</a> - Evaluates the given XPath expression</span></li>
   <li><span class="methodname"><a href="domxpath.evaluate.php" class="methodname" rel="rdfs-seeAlso">DOMXPath::evaluate()</a> - Evaluates the given XPath expression and returns a typed result if possible</span></li>
   <li><span class="methodname"><a href="xsltprocessor.registerphpfunctions.php" class="methodname" rel="rdfs-seeAlso">XSLTProcessor::registerPHPFunctions()</a> - Enables the ability to use PHP functions as XSLT functions</span></li>
   <li><span class="methodname"><a href="xsltprocessor.registerphpfunctionns.php" class="methodname" rel="rdfs-seeAlso">XSLTProcessor::registerPHPFunctionNS()</a> - Register a PHP function as namespaced XSLT function</span></li>
  </ul>
 </div>


</div><?php manual_footer($setup); ?>