Re: Re: replace nested custom html tags
| From: | pierre-yves | Date: | Mon, 05 Nov 2001 12:43:07 +0000 |
| Subject: | Re: Re: replace nested custom html tags | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-73473@lists.php.net to get a copy of this message | ||
Hello,
a bit off topic here but for those using html_entities that would
like to display back the string as html, here is:
function unhtmlentities( $stringHtml ) {
$tmp = get_html_translation_table( HTML_ENTITIES );
$tmp = array_flip ( $tmp );
$stringTmp = strtr ( $stringHtml, $tmp );
return $stringTmp;
}
it seems to work fine, but I did'nt use it enough
to judge yet...
py
----- Original Message -----
From: "Bruce BrackBill" <brackbillbruce@hotmail.com>
To: <elias_bachaalany@yahoo.com>; <php-general@lists.php.net>
Sent: Monday, November 05, 2001 5:25 AM
Subject: [PHP] Re: replace nested custom html tags
>
> Thanks for your response. I didn't think anyone was
> going to touch this one.
>
> I do appreciate your snippet, but I am trying to avoid
> a loop and calling any more regex functions than I have to.
>
> I was really hoping that I could get this into one regexp
> but after scouring the web I do not think it is possible.
>
> Anyone else want to take a stab at this?
>
> Here it is:
> In only 1 preg_replace() -without using arrays as arguments-
> Convert the following line:
>
> [p][b] [u] underlined and bold [/u] [/b] [i] italic [/i][/p]
>
> Into:
> <p><b> <u> underlined and bold </u> </b> <i> italic
> </i></p>
>
> ... while making sure that each tag has a corresonding end tag
> and only replacing the ones that do.
>
> Thanks,
> Bruce
>
>
>
>
> >From: "_lallous" <elias_bachaalany@yahoo.com>
> >To: <brackbillbruce@hotmail.com>
> >Subject: Re: replace nested custom html tags
> >Date: Mon, 5 Nov 2001 12:07:13 +0200
> >
> >try this snippet?
> >
> ><?
> > function replace_tags(&$text)
> > {
> > $re = "/\[([ubi])\](.*?)\[\/(\\1)\]/msi";
> > if (preg_match($re, $text))
> > {
> > $text = preg_replace ($re, "<\\1>\\2</\\1>", $text);
> > replace_tags($text);
> > }
> > }
> >
> > $t = "[b] [u] underlined and bold [/u] [/b] [i] italic [/i]";
> > replace_tags(&$t);
> > echo $t;
> >?>
> >
> >"Bruce Brackbill" <brackbillbruce@hotmail.com> wrote in message
> >news:F114pfeChDKhzrMkrx400005e72@hotmail.com...
> > >
> > > 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
> > >
> >
> >
> >
>
>
> _________________________________________________________________
> 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: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>