高手帮忙看看这个正则该如何写才行?

yueyang 2004-08-24 10:07:15
<sohu_cms_include:learning_articlefrag1><p align=center>  <a href=http://2004.sports.sohu.com/ target=_blank><font color=red><b>搜狐奥运王者归来,七种武器谁与争锋</b></font></a> <a href=http://2004.sports.sohu.com/ target=_blank><img src="http://photo.sohu.com/20040809/Img221437781.gif" height="10" border=0></a></p> </sohu_cms_include>

怎么样把上面的代码中的<sohu_cms_include: 和 </sohu_cms_include>之间的内容用正则取代。

我试了/<sohu*<\/sohu/i 这样不行!
...全文
173 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
Meteorlet 2005-02-02
  • 打赏
  • 举报
回复
对的,用s模式
echo $opf = preg_replace("/<sohu(.*)<\/sohu/s","",$ttt);
ice_berg16 2005-02-02
  • 打赏
  • 举报
回复
.本来就不匹配\n,
在PHP中可以通过/s来使它匹配
cloudchen 2005-02-02
  • 打赏
  • 举报
回复
这里正则中有个很大很大的误解,好像是所有的文档都写错了

.这个字符匹配的是所有字符,但就是除了\n,而所有的文档都说.能匹配任何字符

而且.在[]中是按字面意思来匹配,只能匹配一个点

所以要匹配所有的字符(多行字符),必须要下面这个模式

.|\n
yueyang 2005-02-02
  • 打赏
  • 举报
回复
上面代码不对
$ttt = < < < eof
test
<sohu_cms_include:learning_articlefrag1>
<p align=center >
<a href=http://2004.sports.sohu.com/ target=_blank > <font color=red > <b >搜狐奥运王者归来,七种武器谁与争锋 </b > </font > </a >  <a href=http://2004.sports.sohu.com/ target=_blank > <img src= "http://photo.sohu.com/20040809/Img221437781.gif " height= "10 " border=0 > </a > </p >
</sohu_cms_include>
eof;
echo $opf = preg_replace( "/ <sohu[.\n]* <\/sohu/i ", " ",$ttt);
里面包含\n的情况所以要[.\n],但就是不行!
yueyang 2005-02-02
  • 打赏
  • 举报
回复
都不行啊!
$ttt =<<< eof
test
<sohu_cms_include:learning_articlefrag1><p align=center><a href=http://2004.sports.sohu.com/ target=_blank><font color=red><b>搜狐奥运王者归来,七种武器谁与争锋</b></font></a> <a href=http://2004.sports.sohu.com/ target=_blank><img src="http://photo.sohu.com/20040809/Img221437781.gif" height="10" border=0></a></p> </sohu_cms_include>
eof;
echo $opf = preg_replace("/<sohu[.\n]*<\/sohu/i","",$ttt);
结果还是老样子.
Meteorlet 2005-02-02
  • 打赏
  • 举报
回复
不用s模式就象cloudchen(cloudchen) 那样
ice_berg16 2005-02-01
  • 打赏
  • 举报
回复
/<sohu_cms_include:(.*)<\/sohu_cms_include>/Ui

cloudchen 2005-02-01
  • 打赏
  • 举报
回复
/<sohu_cms_include:.*<\/sohu_cms_include>/
yueyang 2005-02-01
  • 打赏
  • 举报
回复
/<sohu.*<\/sohu/i
这样还是不行
/<sohu.[^<]*<\/sohu/i
这样才行不知为什么?
xuzuning 2004-08-24
  • 打赏
  • 举报
回复
/<sohu*<\/sohu/i
===>
/<sohu.*<\/sohu/i
yueyang 2004-08-24
  • 打赏
  • 举报
回复
直接取?不明白,不用正则不行啊!
张海霖 2004-08-24
  • 打赏
  • 举报
回复
关注,用正则不好.直接取吧

21,893

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧