php – preg_replace导致美元符号被删除

我有一个电子邮件系统,用户在那里写一条消息并发送消息.
我刚发现的主要问题是考虑这个代码
$findEmail = $this->Data->field('body',array('id' => 1610));

    //$getUserEmailTemplate will take frm dbase and e.g: 
    //Hi,@@MESSAGE@@. From: StackOverflow
    //It should change @@MESSAGE@@ part to data from $findEmail (in this example is the $74.97 ...)

    $getUserEmailTemplate = $findUser['User']['email_template'];
    $emailMessage = preg_replace('/\B@@MESSAGE@@\B/u',$findEmail,$getUserEmailTemplate);

    debug($findEmail);
    debug($emailMessage);

并考虑$findemail结果的电子邮件的这个输入:

$74.97
$735.00s

$email消息将导致:

.97
5.00s

我怎样才能解决这个问题?我觉得我的preg_replace模式存在问题.

用户模板可以是任何东西,只要有@@ MESSAGE @@即可,该部分将被更改为用户消息输入.

谢谢

预解析替换文本以在$后面跟一个数字进行转义(记住$n在替换文本中使用时具有特殊含义).请参阅PHP.net文档页面上的 comment

If there’s a chance your replacement text contains any strings such as
“$0.95”,you’ll need to escape those $n backreferences:

<?PHP
  function escape_backreference($x){
    return preg_replace('/\$(\d)/','\\\$$1',$x);
  }
?>

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...