Page 1 of 1

preg_replace and multiple lines?

Posted: Thu Apr 17, 2003 8:34 am
by patrikG
I want to replace text with preg_replace that necessarily includes line-breaks.

How can I have preg_replace support multiple lines, i.e. line-break ("\r\n"). For some reason the parameters "\m" (as suggested on php.net) and "\s" don't work, and including an optional \r\n doesn't do it either - it all works fine with preg_match_all but not with preg_replace

Surely there must be a more elegant solution than to make it a one-line string by doing a preg_split on the string at the line-breaks and imploding it with a linebreak-marker then replace things and put the linebreaks back in?

Hmmm...help? :)

Posted: Thu Apr 17, 2003 9:25 am
by patrikG
Bah. Evil Madmen invented regEx?

Somehow I got it to work, I don't remember what I did.

"/({IF [a-zA-Z_]+ ((=)?(.+|[\r\n]))})/sU"

Great. The sun is shining outside as if it was full blown summer and that's what my afternoon looked like: "/({IF [a-zA-Z_]+ ((=)?(.+|[\r\n]))})/sU".

:twisted: