求一正则表达式,将不是<table<tr<td</td></tr></table>的标签一次替换 表达得不太清楚,不知你是想过滤除<table>以外的html标签,还是过滤掉<table标签的属性 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 (<table<tr<td)(*+)(<table><tr><td>) $reg = "/<[^((table\s+)|(tr\s+)|(td\s+))]*?>/";preg_replace($reg, "", $string); 过滤<table..><tr..><td..></td></tr></table>以外的所有标签 <?php$str='<table width="150" border="1" cellspacing="5" cellpadding="0"><tr><td>留下表格</td></tr></table><p>过滤掉p只留下字</p><div>过滤掉div只留下字</div>';$str=preg_replace('/<(\/?)table([^>]*)>/','<${1}1$2>',$str);$str=preg_replace('/<(\/?)tr([^>]*)>/','<${1}2$2>',$str);$str=preg_replace('/<(\/?)td([^>]*)>/','<${1}3$2>',$str);$str=preg_replace('/<\/?[^123>]+>/','',$str);$str=preg_replace('/<(\/?)1([^>]*)>/','<$1table$2>',$str);$str=preg_replace('/<(\/?)2([^>]*)>/','<$1tr$2>',$str);$str=preg_replace('/<(\/?)3([^>]*)>/','<$1td$2>',$str);echo $str;?> 我用"/\<[^((table)|(tr)|(td)|(\/\td)|\/\tr)|(\/\table))]([^>]{0,})\>/i"这种方法替换,不知道为什么有的能替换,有的却不能替换 舍近求远!strip_tags($text, '<table><tr><th><td>'); 感谢唠叨,还有一个问题,就是我要把<script.....</script>连同两个标签之间的内容一起替换掉,我用/<script([\s\S]*)<\/script>/i我用这种方法替换时,如果页面头部和尾部都有script标签时,那么所有的都替换了,我应该怎样改这段代码,让他一个一个的替换script和标签中的内容呢 用户注册以后,自动发EMAIL到注册用户的邮箱。这个是怎么做 怎么把浏览按钮的浏览两个字改为英文的?? php与lighttpd php中$this的作用范围以及指代哪个对象? 请问,现在做网站大都有后台的吗?是不是用后台来管理网站比较容易?没用过! 这段代码能优化吗? 索引(index)和键名(key)有什么不同? 高分求购代码!!100-500分!! php下的全局变量的奇怪问题? 提取TXT里数据出错 大家都来给点建议:双语言留言板怎么做才好? 用PHP与XML联手进行网站编程[2]
$str='<table width="150" border="1" cellspacing="5" cellpadding="0">
<tr>
<td>留下表格</td>
</tr>
</table>
<p>过滤掉p只留下字</p>
<div>过滤掉div只留下字</div>';$str=preg_replace('/<(\/?)table([^>]*)>/','<${1}1$2>',$str);
$str=preg_replace('/<(\/?)tr([^>]*)>/','<${1}2$2>',$str);
$str=preg_replace('/<(\/?)td([^>]*)>/','<${1}3$2>',$str);
$str=preg_replace('/<\/?[^123>]+>/','',$str);
$str=preg_replace('/<(\/?)1([^>]*)>/','<$1table$2>',$str);
$str=preg_replace('/<(\/?)2([^>]*)>/','<$1tr$2>',$str);
$str=preg_replace('/<(\/?)3([^>]*)>/','<$1td$2>',$str);echo $str;
?>