简体   繁体   English

PHP删除所有表tr td标记

[英]PHP to remove all table tr td tags

I am looking for a way to remove all <table*> <tr*> <td*> </td> </tr> </table> tags from a string. 我正在寻找一种从字符串中删除所有<table*> <tr*> <td*> </td> </tr> </table>标签的方法。 Where the * is a wildcard for anything else. 其中*是其他任何东西的通配符。

What are the regexs for this, so I can use str_replace? 有什么正则表达式,所以我可以使用str_replace?

Just use strip_tags() here: http://php.net/manual/en/function.strip-tags.php 只需在这里使用strip_tags()http//php.net/manual/en/function.strip-tags.php

As long as there are not too many tags that need to be allowed through the filter, it is the easiest way. 只要没有太多标签需要通过过滤器,这是最简单的方法。

可能正则表达式不是最好的解决方案,但试试这个:

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

不要在html上使用正则表达式..将无法正常工作..使用像phpquery这样的东西

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM