- 论坛徽章:
- 0
|
如下面程序,我想把一段字符串中含[MG][/MG]的内容进行替换,比如
aaaaa替换为
<img src=192.168.1.1/images/ad.gif>;
字符串中可能有多个[MG][/MG]
<?php
$S="aaaa[MG]http://192.168.1.1/images/ad.gif[/MG]aaaa[IMG]http://192.168.1.1/images/ad.gif[/MG]";
while(ereg("\[MG\](.+)\[/IMG\]",$S,$regs)){
$found=$regs[1];
echo $found;
echo "<br>;";
$S=ereg_replace("\[MG\]$found\[/MG\]","<br>;<img src='$found'>;<br>;",$S);
}
?>;
为什么不行啊?好像系统把S字符串第一个[MG]和最后一个[/MG]当成符合条件的了
<img src=http://192.168.1.1/images/ad.gif[/MG]aaaa[MG]http://192.168.1.2/images/ad.gif>; |
|