Re: Regular Expression problem
| From: | Ilja Hehenkamp | Date: | Fri, 10 Nov 2000 22:30:11 +0000 |
| Subject: | Re: Regular Expression problem | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-24733@lists.php.net to get a copy of this message | ||
I thought of that, but the reason I want it this way is that if a user
forgets to close a tag the whole layout's screwed up....
So I wanna parse only if [i] AND [/i] exist....
But thanks anyway for your suggestion!
Ilja
"Monte Ohrt" <monte@ispi.net> schreef in bericht
news:3A0C73E8.EFFDA538@ispi.net...
> Hi Ilja,
>
> You could probably figure out some complex regular expression to solve
> this particular problem, although this may not be as quick or as safe as
> breaking things down into managable parts. Maybe you could first search
> and replace your static tags with str_replace, like so:
>
> $bbcode = str_replace("[i]","<i>",$bbcode);
> $bbcode = str_replace("[/i]","</i>",$bbcode);
> $bbcode = str_replace("[/url]","</a>",$bbcode);
> .... (etc, all of your static tags)
>
>
> str_replace() is much faster than regular expression matching, so only
> use ereg_* where absolutely necessary. So after you do this, you are
> left with your dynamic tags, such as [url=...]
>
> example:
> [url=<link>]<i><hyperlink></i></a>
>
> Now go ahead with your ereg_replace for hrefs:
>
> $bbcode = ereg_replace("\[url=([^\]]+)\]","<a href=\\1>",$bbcode);
> ... and so on for any other dynamic tags
>
>
> Monte
>
> Ilja Hehenkamp wrote:
> >
> > Hi,
> >
> > I'm stuck within a regex problem,
> >
> > I know you can match charachters until a character you DON'T want to
match,
> > something like:
> >
> > [^#]*
> >
> > matches all character until a #
> >
> > but what when you wanna list until a whole WORD?
> >
> > Here's my example:
> >
> > $bbcode=eregi_replace("(\[size=)([^]]*)(])([^[/size\]]*)(\[/size\])",
"<font
> > size=\\2>\\4</font>",$bbcode);
> >
> > This searches for [url=<LINK>]<HYPERLINK>[/url] and parses it to <a
> > href="<LINK>"><HYPERLINK></a>
> >
> > the ([^]]*) part is to avoid greediness but now he doesn't parse things
> > like: [url=<link>][i]<hyperlink>[/i][/url] which is logical because he
has
> > to quit when he meets a '['
> >
> > What I want to do that he only stops when he finds: [/url], but
[^[/url]] or
> > [^\[/url\]] doesn't work....
> >
> > Anyone understands what I mean and knows the answer?
> >
> > Thanks!
> >
> > --
> > 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
>
> --
> 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
>