I am trying to replace something at the end of a file, but the replacement is inserted twice. And I don’t understand why.
Demonstration of problem:
$str = "anbncn";
echo preg_replace('/$/', 'inserted', $str);
Returns:
a
b
cinserted <-- !!
inserted
Is it not possible to match the EOF of a string using regexp identifier $
?
I’m not looking for answers how to append strings like .=
. My real use case is the following:
$find = '#(R*??>)?$#';
$insert = addcslashes($insert, '\$').'$1';
$content = preg_replace($find, $insert, $content);