久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

preg_replace 導致美元符號被刪除

preg_replace causing dollar signs get removed(preg_replace 導致美元符號被刪除)
本文介紹了preg_replace 導致美元符號被刪除的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個電子郵件系統,用戶可以在其中寫一條消息,然后發送消息.我剛剛發現的主要問題,考慮這段代碼

I have an email system, where user write a message and it will send the message. The main problem which I just found, consider this code

    $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 結果的電子郵件考慮此輸入:

and consider this input for the email for $findemail result:

$74.97
$735.00s

$email 消息將導致:

$email Message will result in:

.97
5.00s

我該如何解決這個問題?我覺得我的 preg_replace 模式有問題.

How can I fix this? I feel like there's problem with my preg_replace pattern.

用戶模板可以是任何東西,只要有@@MESSAGE@@,那部分就變成了用戶消息輸入.

User template can be anything, as long as there is @@MESSAGE@@ which, that part will be changed to the user message input.

謝謝

推薦答案

預解析替換文本以在后跟數字時轉義 $(記住 $n> 在替換文本中使用時具有特殊含義).請參閱 php.net 文檔頁面上的評論:

Pre-parse the replacement text to escape the $ when followed by a number (remember that $n has special meaning when using in the replacement text). See the comment on the php.net docs page:

如果您的替換文本有可能包含任何字符串,例如$0.95",你需要避開那些 $n 反向引用:

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);
  }
?>

這篇關于preg_replace 導致美元符號被刪除的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cannot use #39;Object as class name as it is reserved Cake 2.2.x(不能使用 Object 作為類名,因為它是保留的 Cake 2.2.x)
Session is lost after an OAuth redirect(OAuth 重定向后會話丟失)
Pagination Sort in Cakephp 3.x(Cakephp 3.x 中的分頁排序)
CakePHP Shared core for multiple apps(CakePHP 多個應用程序的共享核心)
Login [ Auth-gt;identify() ] always false on CakePHP 3(在 CakePHP 3 上登錄 [ Auth-identify() ] 始終為 false)
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)(致命錯誤:允許的內存大小為 134217728 字節已用盡(嘗試分配 87 字節))
主站蜘蛛池模板: 麻豆一区一区三区四区 | 欧美日韩亚洲一区 | 午夜视频网站 | 91亚洲精品国偷拍自产在线观看 | 国产69精品久久99不卡免费版 | 亚洲欧美一区二区三区1000 | 国产一区二区久久久 | 国产 日韩 欧美 中文 在线播放 | 伊人99 | 国产午夜亚洲精品不卡 | 午夜网站视频 | av在线视| 日韩欧美一区二区三区免费观看 | 成人午夜影院 | 中文字幕亚洲一区 | 国产一级在线观看 | 亚洲欧美日韩在线不卡 | 国产精品视频二区三区 | 中文字幕在线一 | 很黄很污的网站 | 成人不卡| 男人天堂久久久 | 成人精品国产免费网站 | 欧美啪啪 | 国产高清在线精品一区二区三区 | 精品免费观看 | 日本电影免费完整观看 | a爱视频 | 91福利影院 | 国产一区二区三区视频在线观看 | 欧美精品在线看 | 色综合天天天天做夜夜夜夜做 | 久久成人国产精品 | 欧美福利| 男女视频在线观看免费 | 三级成人在线 | 操射视频| 欧美视频区 | 日韩av在线播 | 久久视频精品 | 国产片侵犯亲女视频播放 |