如何简化php中的STR替换


how to simplify str replace in php

我有一些这样的内容,我需要替换{{values}}。我怎么能做到这一点在php。如何在一个PHP函数中替换所有字符串?

$mail ="Dear {{ name }} ,
    Your warranty is going to expired in {{ count }} days. Please kindly renew it trhough your dashboard or drop a check. For further details call our sales dept at 1231212121212
    Confirmation id: {{ confid }}
    Warranty Period: {{ Effctivedate }} - {{ Expirydate }}
    Property Address: {{ Address }}";
PHP

echo str_replace('{{ name }}','Test',$mail);

str_replace可以与数组一起使用。

echo str_replace(Array("{{ name }}", "{{ confid }}", ...), Array($name, $confid, ...), $mail);

试试这个

        $mail ="Dear #NAME# ,
            Your warranty is going to expired in #count# days. Please kindly renew it trhough your dashboard or drop a check. For further details call our sales dept at 1231212121212
            Confirmation id:  #confid#
            Warranty Period: #Effctivedate# - #Expirydate#
            Property Address:#Address#";
    $mail= str_replace("#NAME#",$Name,$mail);
    $mail= str_replace("#confid#",$confid,$mail);
    $mail = str_replace("#Effctivedate#",$Effctivedate,$mail);
    $mail = str_replace("#Expirydate#",$Expirydate,$mail);
ecoh $mail;