开发者

Problem with foreach for an array in PHP

while($row = mysql_fetch_object($all)) {
$name = $row->name;
$email = $row->email;
$id = $row->id;

$finished_text = '';
$news_content = '';
$buffer = '';

[...]

foreach($text_in_array as $word) {
    if($word == '[NAME]'){
        $buffer = $name;
    }else if($word == '[NAME].'){
        $buffer = $name.'.';
    }else if($word == '[NAME],'){
        $buffer = $name.',';
    }else if($word == '[NAME]!'){
        $buffer = $name.'!';
    }else if($word == '[NAME]"'){
        $buffer = $name.'"';
    }else if($word == '"[NAME]'){
        $buffer = '"'.$name;
    }else if($word == '"[NAME]"'){
        $buffer = '"'.$name.'"';
    }else if($word == '[NAME]."'){
        $buffer = $name.'."';
    }else if($word == '[NAME],"'){
        $buffer = $name.',"';
    }else if($word == '[NAME]!"'){
        $buffer = $name.'!"';
    }else if($word == '*[NAME]*'){
        $buffer = '*'.$name.'*';
    }else if($word == '**[NAME]**'){
        $buffer = '**'.$name.'**';
    }else if($word == '[EMAIL]'){
 开发者_开发技巧       $buffer = $email;
    }else if($word == '[EMAIL].'){
        $buffer = $email.'.';
    }else if($word == '[EMAIL],'){
        $buffer = $email.',';
    }else if($word == '[EMAIL]!'){
        $buffer = $email.'!';
    }else if($word == '[EMAIL]"'){
        $buffer = $email.'"';
    }else if($word == '"[EMAIL]'){
        $buffer = '"'.$email;
    }else if($word == '"[EMAIL]"'){
        $buffer = '"'.$email.'"';
    }else if($word == '[EMAIL]."'){
        $buffer = $email.'."';
    }else if($word == '[EMAIL],"'){
        $buffer = $email.',"';
    }else if($word == '[EMAIL]!"'){
        $buffer = $email.'!"';
    }else if($word == '*[EMAIL]*'){
        $buffer = '*'.$email.'*';
    }else if($word == '**[EMAIL]**'){
        $buffer = '**'.$email.'**';
    }else{
        $buffer = $word;
    }

    $news_content .= ' '.$buffer;
}
$finished_text .= Markdown($news_content);

[...]

mail(
    'xxxxxxxxxx@gmail.com', //just test later it will be set to $email
    $betreff,
    $message,
    $header
);
}

I don't know why, but sometimes it works perfectly and sometimes it doesn't. Also interesting: Before I created a HTML email with this script, it only worked after I had changed the email address as the last change…

I hope someone can help me. Thanks.


  1. You should be using a switch statement instead of that long string of ifs.
  2. What's wrong with $buffer = str_replace(Array("[NAME]","[EMAIL]"),Array($name,$email),$wort);?
  3. After cleaning that up, if you still get problems, please be more specific on what problems you are having.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜