One of these days where I'm about to question my sanity again...
I don't understand why my regex refuses to match for the optional line break. Code:
$string = 'this is some template {$code}. nice!
{$varinnewline}
{if $bla}1{else}2{/if}
';
echo "<pre>";
preg_replace_callback("/\{([^\}]*)\}(\r\n)?/Us", function($matches) {
print_r($matches);
}, $string);
It produces (among others) this output:
Array
(
[0] => {$varinnewline}
[1] => $varinnewline
)
and not this (which it does if I remove the 0-1 match ? at the end of the regex):
Array
(
[0] => {$varinnewline}
[1] => $varinnewline
[2] =>
)
Basically I want a regex that matches the \r\n at the end of the line if it is available. (I need that because after transforming the {} into < ?php ?> the new line after the ?> seems to be removed by the php interpreter)