php preg_replace 表(也是表中嵌套的表)
如何通过 preg_replace 替换字符串上的所有表?这也意味着嵌套在其他表上的表。目前我正在使用此代码:
$pattern = '/(<table[^>]*>)(.*?)(<\/table>)/is';
但不是“清理”或替换所有表格。
有人有主意吗?
How could I replace via preg_replace a all the tables on a string? That means also the tables nested on other tables. Currently I'm using this code:
$pattern = '/(<table[^>]*>)(.*?)(<\/table>)/is';
but is not "cleaning" or replacing all the tables.
Anybody has an idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,您的正则表达式将匹配表格的打开和嵌套表格的关闭。替换嵌套表有点复杂 - 您到底要用什么来替换它?您打算如何处理嵌套?
如果您要替换 TABLE 标签 - 为什么不单独对待它们,那么用任何内容替换所有开始标签,然后用任何内容替换所有结束标签。这将保持嵌套。
Your regex will match opening of table, and closing of nested table as far as I can see. Replacing nested tables is a little complicated - what are you going to replace it with exactly? How do you plan to handle nesting?
If you are replacing the TABLE tags - why not treat them seperately, so replace all the opening tags with whatever, then all the closing tags with closing whatever. This will maintain the nesting.