Reply to Re: Regular expression that's driving me mad

Your name:

Reply:


Posted by Johnny on 02/28/06 01:21

"Paul Renton" <paul.renton@btconnect.com> wrote in message
news:dtvapm$qu4$1@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
> Hi,
>
> I'm writing a templating system and everything's going great except for my
> main stumbling block. Regular expressions. d:-(
>
> What I'm trying to do is to pick out a starting tag and a finishing tag
with
> anything in-between but the finishing tag. For example:
>
> {#my_tag}
> blah blah blah
> {/#my_tag}
>
> However, if there is another instance of this also on the page like:
>
> {#my_tag}
> blah blah blah
> {/#my_tag}
>
> -- Stuff --
>
> {#my_tag}
> blah blah blah
> {/#my_tag}
>
> I don't want the regex to use the start of the first block and the end of
> the second because that would cut out everything in between.
>
> So what I'm looking for is something similar to:
>
> {#tag_name}[anything that doesn't contain {/#tag_name}]{/#tag_name}
>
>
> I hope this makes sense.
>
>
> Many, many thanks in advance.
>
>

If you are just replacing tags then use str_replace like
$theText = str_replace(array('[b]', '[B]'), '<strong>', $theText);
and do that for each different tag.

From what I've read the problem you describe is to do
with POSIX regular expression being greedy,
that is they match the most characters they can and if that means
skipping over closing tags until another is found it will and you could end
up with a whole page or more in there.
I've never used it but apparently you can use Perl-Compatible Regular
Expressions (PCRE) to help with this.
http://php.net/pcre

enjoy! :-)

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация