xsltprocessor.registerphpfunctions.html
来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 121 行
HTML
121 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Enables the ability to use PHP functions as XSLT functions</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div 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">(No version information available, might be only in CVS)</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"> <h3 class="title">Description</h3> <div class="classsynopsis"> <div class="ooclass"><a href="class.xsltprocessor.html" class="classname">XSLTProcessor</a></div> <div class="methodsynopsis dc-description"> <span class="type">void</span> <span class="methodname"><b><b>registerPHPFunctions</b></b></span> ([ <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <tt class="parameter">$restrict</tt></span> ] )</div> </div> <p class="para"> This method enables the ability to use PHP functions as XSLT functions within XSL stylesheets. </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">restrict</tt></i></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"> <h3 class="title">Return Values</h3> <p class="para"> No value is returned. </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 Simple PHP Function call from a stylesheet</b></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: #0000BB"><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: #0000BB"><?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"> <h3 class="title">ChangeLog</h3> <p class="para"> <table class="informaltable"> <colgroup> <thead valign="middle"> <tr valign="middle"> <th colspan="1">Version</th> <th colspan="1">Description</th> </tr> </thead> <tbody valign="middle" class="tbody"> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">5.1.0</td> <td colspan="1" rowspan="1" align="left"> The <i><tt class="parameter">restrict</tt></i> parameter was added. </td> </tr> </tbody> </colgroup> </table> </p> </div></div><hr /><div 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>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?