Jump to content


Photo

Preg Split not matching with linebreaks


  • Please log in to reply
2 replies to this topic

#1 Pezzoni

Pezzoni
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 02 April 2006 - 09:45 PM

I have the following preg_split command at the moment:
preg_split('/(\{loop \$.+ as \$.+\}.+?\{endloop\})/', $this->template_file, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);

Now this works great, so long as the text to be matched is all on the same line. For example:
{loop $waa as $wai}{$wai[one]}{$wai[two]}{endloop}
All works fine.

However, unfortunately, if the contained statements are split onto different lines, the preg_split statement stops working properly, so this will not work for example:
{loop $waa as $wai}
    {$wai[one]}
    {$wai[two]}
{endloop}

All of which is a little annoying!

Any help would be gratefully recieved!

Thanks.

#2 Pezzoni

Pezzoni
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 03 April 2006 - 03:42 PM

Any ideas?

Thanks.

#3 Pezzoni

Pezzoni
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 03 April 2006 - 05:10 PM

Fixed this one with:
        $pieces = preg_split('/(\{loop \$.+ as \$.+\}(?s:.+?)\{endloop\})/', $this->template_file, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users