Hi,

Anyone have any ideas on how I could modify
the following to work on nested tags?

The regex replaces custom tags [i] [u] [b]
with real tags.

The Regex takes any of the characters in the class \[([ubi])\]
then non greedily matches any character (.*?) then matches
the result of the first reference from the character
class \[\/(\\1)\]/ . It then replaces the [u]stuff[/u] to
<u>stuff</u> etc.

Everthing works fine, except when the tags are nested.

I'm actually suprised that you can use a reference ( eg: \\1 )
in the pattern and not only in the replacement.  There does
not seam to be any mention of that anywhere.  The use of
references in the pattern does not appear to be related
in any way the the problem.


echo preg_replace ("/\[([ubi])\](.*?)\[\/(\\1)\]/msi","<\\1>\\2</\\1>",
           " [b] [u] underlined and bold [/u] [/b] [i] italic [/i]");


The output:( it doesn't replace the nested [u] [/u] ):

<b> [u] underlined and bold [/u] </b> <i> italics </i>

Thanks,
Bruce



_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to