PHP删除所有表tr td标记


PHP to remove all table tr td tags

我正在寻找一种从字符串中删除所有<table*> <tr*> <td*> </td> </tr> </table>标记的方法。其中*是其他任何事物的通配符。

什么是regexs,所以我可以使用str_replace?

只需在此处使用strip_tags():http://php.net/manual/en/function.strip-tags.php

只要没有太多的标签需要通过过滤器,这是最简单的方法。

可能regex不是最好的解决方案,但请尝试以下方法:

echo preg_replace('/'<['/]?(table|tr|td)([^'>]*)'>/i', '', $text);

不要在html上使用regex。。不起作用。。使用类似phpquery 的东西