Php正则表达式重复替换字符串的结尾($)

I have the code below to add at the end of source string the string "QWE":

<?php
echo preg_replace('/$/','QWE',"<p>123</p>    
<p>456</p>
"
)
?>

The result is:

# php p.php
<p>123</p>    
QWE456</p>
QWE

The result must be like below:

# php p.php
<p>123</p>    
456</p>
QWE

May be something wrong?

UPDATE

Thanks all for suggestions.

After some tests I've found the temporary solution. If I replace the double quotes to single quotes the result is ok.

But I couldn't understand why the double quotes string behaves so strange.

Instead of $ use \z for end of input in multiline input data:

echo preg_replace('/\z/','QWE','<p>123</p>

<p>456</p>'."
"
);

OUTPUT:

<p>123</p>

<p>456</p>
QWE