For Programmers: Free Programming Magazines  


Home > Archive > PHP Documentation > June 2006 > cvs: phpdoc /en/reference/pcre/functions preg-replace-callback.xml









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author cvs: phpdoc /en/reference/pcre/functions preg-replace-callback.xml
Etienne Kneuss

2006-06-24, 8:03 am

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/phpdo...3&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.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com