作者tnsshnews (tnsshnews)
看板PHP
标题[请益]要怎样将特定的html tag所包夹的字串清掉
时间Thu Dec 30 11:10:13 2010
html source:
<p>These days, robots are more common than you might think. Consider the Roomba, a programmable robotic vacuum which cleans floors on its own.<br /><br />"We wanted to make something simple that people could use every day," says Helen Greiner, co-founder of iRobot, the company that makes the smart vacuum. "And that\'s what inspired us to build the Roomba." <div class=\'boxout photo230px\'><img src="
http://media.voanews.com/images/230*173/inline-US_ROBOT_CONVENTION_04.jpg" width="230" height="173"
alt="Some robots, like the Roomba - a programmable robotic vacuum which cleans floors on its own - are already commonplace in many US households. " title="Some robots, like the Roomba - a programmable robotic vacuum which cleans floors on its own - are already commonplace in many US households. " border="0" /><h6 class=\'credit\'>iRobot</h6><span class=\'caption\'>Some robots, like the Roomba - a programmable robotic vacuum which cleans floors on its own - are already commonplace in many US
households.</span></div></p>'
想清掉被<div> </div>包含的字
但<div>里面有时候又会放一些属性,
我试了好多个php regex还是都失败, 拜托高手指点
my trial:
preg_replace("/<div[.*]>[.*]<\/div>/i","", $string);
ps. regex好难
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.109.21.229
1F:→ buganini:[]不是这样用的 12/30 11:31
2F:→ buganini:/<div.*?>.*?<\/div>/ or /<div[^>]*>.*?<\/div>/ 12/30 11:32
3F:→ buganini:後者效能较好 12/30 11:32
4F:→ tnsshnews:我刚才试过完全没有任何处理ㄟ....还是一样在@@ 12/30 13:04
6F:→ tnsshnews:regex只能用try的? 12/30 14:41
7F:→ MOONRAKER:你现在不try就永远只能用try的。 12/31 11:47
8F:→ MOONRAKER:踹了一下(这点我强调)发现,div後面不加上\s+就match 12/31 11:53
9F:→ MOONRAKER:不到,所以写成土土的<(div\s+[^>]*)|(div)>.*?<\/div> 12/31 11:54
10F:→ MOONRAKER:…不对,要<((div\s+[^>]*)|(div))>.*?<\/div>才行 12/31 11:55
11F:→ chrisQQ:应该不是说用try的啦… 只是因为你的资料(看起来)很复杂 12/31 14:26
12F:→ chrisQQ:你可以用这个flash先一步一步的把 <div> </div> parse出来 12/31 14:26
13F:→ chrisQQ:在慢慢延伸变化到你想要的。另外,右边有很多网友提供的 12/31 14:27
14F:→ chrisQQ:regex 可以套用,你可以试试看符不符合你的需求~ 12/31 14:27
15F:→ chrisQQ:不过说到底也是我没有这麽熟悉regex啦,所以只好用try的QQ 12/31 14:29
16F:推 buganini:我忘了加modifier... 後面的/後面加个s吧 再加个i也可 01/06 19:38