$string = 'This is some text and images
<img src="http://linktoimage" border="0">,
more text and <img src="http://linktoanotherimage"> and so on';
print preg_replace('/<img(.*)>/i','',$string,1);
上記のあなたはそれがあまりにも、スペースや改行で始まる、コンマや改行サフィックス(とあなたがこれらを削除することがあります知っていると仮定すると、
This is some text and images
,
more text and <img src="http://linktoanotherimage"> and so on
を返す必要があります)、あなたはあなたの
This is some text and images more text and <img src="http://linktoanotherimage"> and so on
を与えるどの
print preg_replace("/\n <img(.*)>\,\n /i",'',$string,1);
を行うことができます
出典
2012-01-04 19:25:57
kba
あなたの文字列は実際には正規であるため、単純な正規表現でこれを実行できます。それを試してください、そしてあなたが立ち往生したときに、これまでに書いたことを投稿してください。 – meagar