求一正则表达式,将不是<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和标签中的内容呢 求一段正则替换.. 如何用php实现无跳转的跨域上传? 使用cookie时提示Notice: Undefined index 求 抽奖算法 PHP 与ORACLE链接问题 哪位大哥帮帮小弟:这好象是php本身的原因!!! 如何实现不要重新查询的分页显示? 类初始化的一个问题 谁有用PHP写的UBB正则表达式啊? 求 大家都来给点建议:双语言留言板怎么做才好? 用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;
?>