<HTML ><HEAD ><TITLE >Output Filters</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Smarty Manual" HREF="index.html"><LINK REL="UP" TITLE="Extending Smarty With Plugins" HREF="plugins.html"><LINK REL="PREVIOUS" TITLE="Prefilters/Postfilters" HREF="plugins.prefilters.postfilters.html"><LINK REL="NEXT" TITLE="Resources" HREF="plugins.resources.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="sect1" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Smarty Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="plugins.prefilters.postfilters.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Chapter 16. Extending Smarty With Plugins</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="plugins.resources.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="plugins.outputfilters" ></A >Output Filters</H1 ><P > Output filter plugins operate on a template's output, after the template is loaded and executed, but before the output is displayed. </P ><DIV CLASS="funcsynopsis" ><A NAME="AEN7377" ></A ><P ></P ><P ><CODE ><CODE CLASS="FUNCDEF" >string <B CLASS="function" >smarty_outputfilter_<TT CLASS="replaceable" ><I >name</I ></TT ></B ></CODE > (string $template_output, object &$smarty)</CODE ></P ><P ></P ></DIV ><P > The first parameter to the output filter function is the template output that needs to be processed, and the second parameter is the instance of Smarty invoking the plugin. The plugin is supposed to do the processing and return the results. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7387" ></A ><P ><B >Example 16-9. An output filter plugin</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">/*<br /> * Smarty plugin<br /> * -------------------------------------------------------------<br /> * File: outputfilter.protect_email.php<br /> * Type: outputfilter<br /> * Name: protect_email<br /> * Purpose: Converts @ sign in email addresses to %40 as<br /> * a simple protection against spambots<br /> * -------------------------------------------------------------<br /> */<br /> </span><span style="color: #007700">function </span><span style="color: #0000BB">smarty_outputfilter_protect_email</span><span style="color: #007700">(</span><span style="color: #0000BB">$output</span><span style="color: #007700">, &</span><span style="color: #0000BB">$smarty</span><span style="color: #007700">)<br /> {<br /> return </span><span style="color: #0000BB">preg_replace</span><span style="color: #007700">(</span><span style="color: #DD0000">'!(\S+)@([a-zA-Z0-9\.\-]+\.([a-zA-Z]{2,3}|[0-9]{1,3}))!'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'$1%40$2'</span><span style="color: #007700">, </span><span style="color: #0000BB">$output</span><span style="color: #007700">);<br /> }<br /></span><span style="color: #0000BB">?></span> </span> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P > See also <A HREF="api.register.outputfilter.html" > <TT CLASS="varname" >register_outputfilter()</TT ></A >, <A HREF="api.unregister.outputfilter.html" > <TT CLASS="varname" >unregister_outputfilter()</TT ></A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="plugins.prefilters.postfilters.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="plugins.resources.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Prefilters/Postfilters</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="plugins.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Resources</TD ></TR ></TABLE ></DIV ></BODY ></HTML >