|
Posted by Fred!head on 07/27/06 06:37
Thanks!
Tim
Benjamin Esham wrote:
> Fred!head wrote:
>
> > Benjamin Esham wrote:
> >
> > > timslavin wrote:
> > >
> > > > First, I want to grab data between two markers that I define (e.g.
> > > > <start> ... data here ... </start> and strip of the text before the
> > > > first marker (<start> in this example) and after the second marker
> > > > (</start>) in this example. That would leave me with the "... data
> > > > here ..." chunk with my markers either included (worst case) or
> > > > removed (best case, saving me the third step below).
> > >
> > > $pieces = preg_split('/\<(\/)?start\>/', $input);
> >
> > Probably it's the fact my mind goes blank when reading about regular
> > expressions but I'm not able to make the preg_split work. If you have
> > time/interest, I'd appreciate any additional thoughts.
>
> Whoops, I completely forgot that your opening tag has attributes! Sorry
> about that. Try this:
>
> $pieces = preg_split('/\<(@content[^>]*|\/content@)\>/', $input);
>
> > What modifications to the preg_split do I need to make this work? Is there
> > a cleaner way to set up the <content> tags, like </content> instead of
> > </content@> that would make the regular expression more efficient?
>
> Actually, if you used, for example, <@content> for both the start and the
> end, you could simply do
>
> $pieces = explode('<@content>', $input);
>
> and bypass regular extensions altogether. The resulting array will be set
> up the same as before. If you are able to modify the input to make both
> tags the same, this would probably be the best solution.
>
> HTH,
> --
> Benjamin D. Esham
> bdesham@gmail.com | AIM: bdesham128 | Jabber: same as e-mail
> ...and that's why I'm not wearing any pants.
Navigation:
[Reply to this message]
|