RegEx (php) - unite lines in multiline replacement

Posted by Qiao on Stack Overflow See other posts from Stack Overflow or by Qiao
Published on 2010-04-11T17:47:35Z Indexed on 2010/04/11 17:53 UTC
Read the original article Hit count: 227

Filed under:
|

I need change background of all text that have two spaces from the start of the line.

  text

shold be converted to "<div class='special'>text</div>"

That is easy:

$text = preg_replace("|^  (.+)|um", "<div class='special'>$1</div>", $text);

But

  line1
  line2

Is converted to

<div class='special'>line1</div>
<div class='special'>line2</div>

Though

<div class='special'>line1
line2</div>

is needed.

How that can be achieved?

© Stack Overflow or respective owner

Related posts about regex

Related posts about php