|
|
@@ -0,0 +1,53 @@
|
|
|
+<?xml version="1.0" encoding="UTF-8"?>
|
|
|
+<!-- Reviewed: no -->
|
|
|
+<sect2 id="zend.filter.set.pregreplace">
|
|
|
+ <title>PregReplace</title>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ <classname>Zend_Filter_PregReplace</classname> performs a search using regular expressions
|
|
|
+ and replaces all found elements.
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ The option <property>match</property> has to be given to set the pattern which will be
|
|
|
+ searched for. It can be a string for a single pattern, or an array of strings for multiple
|
|
|
+ pattern.
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ To set the pattern which will be used as replacement the option <property>replace</property>
|
|
|
+ has to be used. It can be a string for a single pattern, or an array of strings for multiple
|
|
|
+ pattern.
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <programlisting language="php"><![CDATA[
|
|
|
+$filter = new Zend_Filter_PregReplace(array('match' => 'bob', 'replace' => 'john'));
|
|
|
+$input = 'Hy bob!";
|
|
|
+
|
|
|
+$filter->filter($input);
|
|
|
+// returns 'Hy john!'
|
|
|
+]]></programlisting>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ You can use <methodname>getMatchPattern()</methodname> and
|
|
|
+ <methodname>setMatchPattern()</methodname> to set the matching pattern afterwards. To set
|
|
|
+ the replacement pattern you can use <methodname>getReplacement()</methodname> and
|
|
|
+ <methodname>setReplacement()</methodname>.
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <programlisting language="php"><![CDATA[
|
|
|
+$filter = new Zend_Filter_PregReplace();
|
|
|
+$filter->setMatchPattern(array('bob', 'Hy'))
|
|
|
+ ->setReplacement(array('john', 'Bye'));
|
|
|
+$input = 'Hy bob!";
|
|
|
+
|
|
|
+$filter->filter($input);
|
|
|
+// returns 'Bye john!'
|
|
|
+]]></programlisting>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ For a more complex usage take a look into <acronym>PHP</acronym>'s <ulink
|
|
|
+ linkend="http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php">PCRE
|
|
|
+ Pattern Chapter</ulink>.
|
|
|
+ </para>
|
|
|
+</sect2>
|