开发者

Problem with foreach for an array in PHP

开发者 https://www.devze.com 2023-04-08 20:10 出处:网络
while($row = mysql_fetch_object($all)) { $name = $row->name; $email = $row->email; $id = $row->id;
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

精彩评论

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

关注公众号