Help! I’m doing a replace that will convert a bracketed block to a block surrounded by <div>s. Please see below.
The code:
$data = '
<p>
{
asdf
asdf
asdf
}
</p>
';
echo preg_replace('%{(.*)}%m', '<div>\1</div>', $data);
The output should be:
<p>
<div>
asdf
asdf
asdf
</div>
</p>
What am I doing wrong here?
Use the
smodifier instead of themmodifier.The
smodifier allows.to match newlines.The
mmodifier makes^and$match the start and end of individual lines, as opposed to the start and end of the entire string.Side-note: The preferred syntax for the replacement is
<div>$1</div>