Preg replace does not work with captured settings and & lt;


When I add the less than "<" symbol

$str = 'test';
$str = preg_replace('@(.*)@isu', '<$1', $str);
echo $str; // outputs ""

It should output <test, but instead outputs nothing.

It works fine when I don't add the character.

$str = 'test';
$str = preg_replace('@(.*)@isu', '$1', $str);
echo $str; // outputs "test"

I tried escaping it

$str = 'test';
$str = preg_replace('@(.*)@isu', '<\\\\$1', $str);
echo $str; // outputs "<\test"

I was unable to find anything about this in the php manual while google just spits out unrelated SO questions.

I would like to know why this does not work?

PHP 5.4.22

I think you are checking the outputs from the browser. That's why its doing such behaviour. From the console it works perfectly. So, I believe you'll find everything when you view the source of html from browser.

Also, you can replace the < with &lt;