この最初の文字列の位置が.pngの場合は 、次にhaystackから$ png1を取得しますが、最初の文字列の位置が.jpgの場合は$ haystackのjpg1ですが、.gifの場合はhaystackから$ gif1を取得し、そうでなければ文字列の位置は.bmpです。$ bmp1を取得します。文の構文解析が正しくない場合
これは私が試したものですが、 tは正しく解析:
<?php
// 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);
}
?>
例$html_part
を、表示のために追加の改行と、次のとおりです。
<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:[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]">`
'正しく解析されません。あなたは未知の外部HTMLをつかんでいますか? –
このコードは不必要に畳み込まれているように見えます。あなたはあなたの意図を投稿できますか? – Halcyon
ポール、はい私は外部HTMLをつかんでいますが、スクリプトによって期待どおりにフォーマットが出るような特定のルールがユーザに提供されていることが知られています。問題は、正しい画像が得られないということです。すべてが上記のようなものを除いて、次のブロックのコードにちょうど従います。 $ png2、$ jpg2などを2番目の画像に追加します。上のコードは最初の画像/ –