colder Wed Jun 21 17:08:39 2006 UTC
Modified files:
/phpdoc/en/reference/pcre/functions preg-replace-callback.xml
Log:
New example using recursion
http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pcre/functions/preg-replace-callback.xml?r1=1.12&r2=1.13&diff_format=u
Index: phpdoc/en/reference/pcre/functions/preg-replace-callback.xml
diff -u phpdoc/en/reference/pcre/functions/preg-replace-callback.xml:1.12
phpdoc/en/reference/pcre/functions/preg-replace-callback.xml:1.13
--- phpdoc/en/reference/pcre/functions/preg-replace-callback.xml:1.12 Mon Apr
3 15:10:11 2006
+++ phpdoc/en/reference/pcre/functions/preg-replace-callback.xml Wed Jun
21 17:08:39 2006
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.12 $ -->
+<!-- $Revision: 1.13 $ -->
<!-- splitted from ./en/functions/pcre.xml, last change in rev 1.47 -->
<refentry id="function.preg-replace-callback">
<refnamediv>
@@ -90,6 +90,33 @@
]]>
</programlisting>
</example>
+ <example>
+ <title><function>preg_replace_callback</function> using recursive structure
+ to handle encapsulated BB code</title>
+ <programlisting role='php'>
+<![CDATA[
+<?php
+$input = "plain [indent] deep [indent] deeper [/indent] deep [/indent] plain";
+
+function parseTagsRecursive($input)
+{
+
+ $regex = '#\[indent]((?:[^[]|\[(?!/?indent])|(?R))+)\[/indent]#';
+
+ if (is_array($input)) {
+ $input = '<div style="margin-left: 10px">'.$input[1].'</div>';
+ }
+
+ return preg_replace_callback($regex, 'parseTagsRecursive', $input);
+}
+
+$output = parseTagsRecursive($input);
+
+echo $output;
+?>
+]]>
+ </programlisting>
+ </example>
<note>
<para>
<parameter>count</parameter> parameter is available since PHP 5.1.0.