このif文を次のようにして取得しようとしています。最初の文字列の位置が.pngの場合、haystackから$ png1を取得しますが、最初の文字列の位置が.jpgの場合、 haystackから$ jpg1を取得しますが、それが.gifの場合はhaystackから$ gif1を取得し、そうでなければ文字列の位置は.bmpですので$ bmp1を取得します。/else/elseif文の構文解析が正しくない場合
これは私が試したものですが、それは、正しく解析しません:
/***************************** 1st image in email**********************************/
// if first occurence is .png get $png1 needle from haystack
if (preg_match('/cid:([^"@]*)[email protected]([^"]*)/', $html_part))
{ $find = '/cid:([^"@]*)[email protected]([^"]*)/';
$replace1 = $png1;
$html_part = preg_replace($find, $replace, $html_part);
}
// if first occurence is .jpg get $jpg1 needle from haystack
elseif (preg_match('/cid:([^"@]*)[email protected]([^"]*)/', $html_part))
{ $find = '/cid:([^"@]*)[email protected]([^"]*)/';
$replace1 = $jpg1;
$html_part = preg_replace($find, $replace, $html_part);
}
// if first occurence is .gif then get $gif1 needle from haystack
elseif (preg_match('/cid:([^"@]*)[email protected]([^"]*)/', $html_part))
{ $find = '/cid:([^"@]*)[email protected]([^"]*)/';
$replace = $gif1;
$html_part = preg_replace($find, $replace, $html_part);
}
// if first occurence is .bmp then get $bmp1 needle from haystack
else
{ $find = '/cid:([^"@]*)[email protected]([^"]*)/';
$replace = $bmp1;
$html_part = preg_replace($find, $replace, $html_part);
}
と5枚の画像の合計のために示さ繰り返し 問題は、私が望んでいただろうとの文が返されない場合です。彼らはただで、表示のために追加改行で、
例の$ html_part(これを5回繰り返すの規模で)全体のシーケンスにマッチした最後のものとの参照を置き換えます
<b>Bold Text.</b> <i>Italicized Text.</i> <u>Underlined Text.</u> Plain Unformatted Text. <img width=183 height=183 id="Picture_x0020_3" src="cid:[email protected]" alt="Description: Description: Description: cid:[email protected]"> <img width=153 height=145 id="Picture_x0020_2" src="cid:image002[email protected]" alt="Description: Description: cid:[email protected]"><img width=182 height=123 id="Picture_x0020_1" src="cid:[email protected]" alt="Description: Description: cid:[email protected]">
誰かが私にこの解決策を見つけるのを助けることができますか?ありがとう
重複。 http://stackoverflow.com/questions/9086942/if-statement-parsing-incorrectly#comment11410443_9086942 –
['preg_replace_callback'](http://php.net/preg_replace_callback)と'/cid :(コピー&ペーストの代わりに[^ "@] *)。(gif | bmp | jpeg | png)@([^"] *)/ ''ループ(および場合によっては配列)は、5つの画像すべての処理を統合することができます。 – mario
質問は重複しないでください。これを削除してください。 – hakre