<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Enables the ability to use PHP functions as XSLT functions</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="xsltprocessor.importstylesheet.html">XSLTProcessor::importStylesheet</a></div> <div class="next" style="text-align: right; float: right;"><a href="xsltprocessor.removeparameter.html">XSLTProcessor::removeParameter</a></div> <div class="up"><a href="class.xsltprocessor.html">XSLTProcessor</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="xsltprocessor.registerphpfunctions" class="refentry"> <div class="refnamediv"> <h1 class="refname">XSLTProcessor::registerPHPFunctions</h1> <p class="verinfo">(PHP 5 >= 5.0.4)</p><p class="refpurpose"><span class="refname">XSLTProcessor::registerPHPFunctions</span> — <span class="dc-title">Enables the ability to use PHP functions as XSLT functions</span></p> </div> <div class="refsect1 description" id="refsect1-xsltprocessor.registerphpfunctions-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type"><span class="type void">void</span></span> <span class="methodname"><strong>XSLTProcessor::registerPHPFunctions</strong></span> ([ <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$restrict</code></span> ] )</div> <p class="para rdfs-comment"> This method enables the ability to use PHP functions as XSLT functions within XSL stylesheets. </p> </div> <div class="refsect1 parameters" id="refsect1-xsltprocessor.registerphpfunctions-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">restrict</code></em></span> <dd> <p class="para"> Use this parameter to only allow certain functions to be called from XSLT. </p> <p class="para"> This parameter can be either a string (a function name) or an array of functions. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-xsltprocessor.registerphpfunctions-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> No value is returned. </p> </div> <div class="refsect1 examples" id="refsect1-xsltprocessor.registerphpfunctions-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-5540"> <p><strong>Example #1 Simple PHP Function call from a stylesheet</strong></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$xml </span><span style="color: #007700">= <<<EOB<br /></span><span style="color: #DD0000"><allusers><br /> <user><br /> <uid>bob</uid><br /> </user><br /> <user><br /> <uid>joe</uid><br /> </user><br /></allusers><br /></span><span style="color: #007700">EOB;<br /></span><span style="color: #0000BB">$xsl </span><span style="color: #007700">= <<<EOB<br /></span><span style="color: #DD0000"><?xml version="1.0" encoding="UTF-8"?><br /><xsl:stylesheet version="1.0" <br /> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"<br /> xmlns:php="http://php.net/xsl"><br /><xsl:output method="html" encoding="utf-8" indent="yes"/><br /> <xsl:template match="allusers"><br /> <html><body><br /> <h2>Users</h2><br /> <table><br /> <xsl:for-each select="user"><br /> <tr><td><br /> <xsl:value-of<br /> select="php:function('ucfirst',string(uid))"/><br /> </td></tr><br /> </xsl:for-each><br /> </table><br /> </body></html><br /> </xsl:template><br /></xsl:stylesheet><br /></span><span style="color: #007700">EOB;<br /></span><span style="color: #0000BB">$xmldoc </span><span style="color: #007700">= </span><span style="color: #0000BB">DOMDocument</span><span style="color: #007700">::</span><span style="color: #0000BB">loadXML</span><span style="color: #007700">(</span><span style="color: #0000BB">$xml</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$xsldoc </span><span style="color: #007700">= </span><span style="color: #0000BB">DOMDocument</span><span style="color: #007700">::</span><span style="color: #0000BB">loadXML</span><span style="color: #007700">(</span><span style="color: #0000BB">$xsl</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$proc </span><span style="color: #007700">= new </span><span style="color: #0000BB">XSLTProcessor</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$proc</span><span style="color: #007700">-></span><span style="color: #0000BB">registerPHPFunctions</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$proc</span><span style="color: #007700">-></span><span style="color: #0000BB">importStyleSheet</span><span style="color: #007700">(</span><span style="color: #0000BB">$xsldoc</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$proc</span><span style="color: #007700">-></span><span style="color: #0000BB">transformToXML</span><span style="color: #007700">(</span><span style="color: #0000BB">$xmldoc</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div></div> </div> </p> </div> <div class="refsect1 changelog" id="refsect1-xsltprocessor.registerphpfunctions-changelog"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>5.1.0</td> <td> The <em><code class="parameter">restrict</code></em> parameter was added. </td> </tr> </tbody> </table> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="xsltprocessor.importstylesheet.html">XSLTProcessor::importStylesheet</a></div> <div class="next" style="text-align: right; float: right;"><a href="xsltprocessor.removeparameter.html">XSLTProcessor::removeParameter</a></div> <div class="up"><a href="class.xsltprocessor.html">XSLTProcessor</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>