0

最初のstr_replaceものは問題なく動作しますが、次の 2 つは処理されません。置換変数と置換文字列がすべて存在/エコーであることをテストしました。それぞれに一意のものが必要$body.ですか?

        $body.= "--$mime_boundary\n";
        $body.= "Content-Type: text/html; charset=\"UTF-8\"\n";
        $body.= "Content-Transfer-Encoding: 7bit\n\n";    
        $body.= str_replace("%%user%%",$en['user'],$html_content);
        $body.= str_replace("%%confcode%%",$en['confcode'],$html_content);
        $body.= str_replace("%%memb_id%%",$en['memb_id'],$html_content);    
        $body.= "\n\n";
        $body.= "--$mime_boundary--\n";
4

3 に答える 3

3

試す

    $body.= str_replace(
        array(
            "%%user%%",
            "%%confcode%%",
            "%%memb_id%%"
        ), 
        array(
            $en['user'],
            $en['confcode'],
            $en['memb_id']
        ),
        $html_content
    );

それ以外の

    $body.= str_replace("%%user%%",$en['user'],$html_content);
    $body.= str_replace("%%confcode%%",$en['confcode'],$html_content);
    $body.= str_replace("%%memb_id%%",$en['memb_id'],$html_content); 
于 2013-09-12T19:04:09.527 に答える
0

同じ内のすべての文字列を置き換えたいと思います$html_contentか?

replaceそのため、それらをすべて機能させるために、すでに処理された文字列を呼び出す必要があります。

    $body.= "--$mime_boundary\n";
    $body.= "Content-Type: text/html; charset=\"UTF-8\"\n";
    $body.= "Content-Transfer-Encoding: 7bit\n\n";    
    $html_content= str_replace("%%user%%",$en['user'],$html_content);
    $html_content= str_replace("%%confcode%%",$en['confcode'],$html_content);
    $body.= str_replace("%%memb_id%%",$en['memb_id'],$html_content);    
    $body.= "\n\n";
    $body.= "--$mime_boundary--\n";

これにより、 が変更されることに注意してください$html_content。それが望ましくない場合は、別の変数を使用して結果を割り当てるか、Mark Ba​​ker のソリューションを使用してください。

于 2013-09-12T19:04:44.563 に答える