求一个替换

cyr11 2010-07-20 05:05:11

$a=<<<html
<img style="cursor: pointer" height="523" alt="" width="750" border="0" onclick="window.open('/uploads/allimg/2010/06/100702/45_100702154730_4.jpg')" src="/uploads/allimg/2010/06/100702/45_100702154730_4.jpg" />
html;

我要替换成
<img src="http://www.phpzy.com/uploads/allimg/2010/06/100702/45_100702154730_4.jpg" />

替换是<img (.*) src="(.*)/uploads/allimg/2010/06/100702/45_100702154730_4.jpg" (.*)/>



图片加一个域名http://www.phpzy.com,图片是不固定的!

最后结果如<img src="http://www.phpzy.com/uploads/allimg/2010/06/100702/45_100702154730_4.jpg" />


如$b=<<<html
<img style="cursor: pointer" height="523" alt="" width="750" border="0" onclick="window.open('/uploads/allimg/2010/06/100702/45_100702154730_3.jpg')" src="/uploads/allimg/2010/06/100702/45_100702154730_3.jpg" />
html;

最后结果如<img src="http://www.phpzy.com/uploads/allimg/2010/06/100702/45_100702154730_3.jpg" />


...全文
26 点赞 收藏 2
写回复
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2010-07-20
$b =<<< html
<img style="cursor: pointer" height="523" alt="" width="750" border="0" onclick="window.open('/uploads/allimg/2010/06/100702/45_100702154730_3.jpg')" src="/uploads/allimg/2010/06/100702/45_100702154730_3.jpg" />
<img style="cursor: pointer" height="523" alt="" width="750" border="0" onclick="window.open('/uploads/allimg/2010/06/100702/45_100702154730_4.jpg')" src="/uploads/allimg/2010/06/100702/45_100702154730_4.jpg" />

html;

echo preg_replace('/<img.+src=(".+?").*\/>/', '<img src=$1 />', $b);


<img src="/uploads/allimg/2010/06/100702/45_100702154730_3.jpg" />
<img src="/uploads/allimg/2010/06/100702/45_100702154730_4.jpg" />
回复
amani11 2010-07-20


$a=<<<html
<img style="cursor: pointer" height="523" alt="" width="750" border="0" onclick="window.open('/uploads/allimg/2010/06/100702/45_100702154730_4.jpg')" src="/uploads/allimg/2010/06/100702/45_100702154730_4.jpg" /><img style="cursor: pointer" height="523" alt="" width="750" border="0" onclick="window.open('/uploads/allimg/2010/06/100702/45_100702154730_4.jpg')" src="/uploads/allimg/2010/06/100702/45_100702154730_4.jpg" /><img style="cursor: pointer" height="523" alt="" width="750" border="0" onclick="window.open('/uploads/allimg/2010/06/100702/45_100702154730_4.jpg')" src="/uploads/allimg/2010/06/100702/45_100702154730_4.jpg" />
html;




echo preg_replace('/<img(.*?)src=\"(.*?)\"\s*\/>/isx', "<img src=\"http://www.phpzy.com$2\" />", $a);

回复
发动态
发帖子
基础编程
创建于2007-09-28

2.1w+

社区成员

从PHP安装配置,PHP入门,PHP基础到PHP应用
申请成为版主
社区公告
暂无公告