php匹配嵌套标签有问题,

dnpao 2017-05-16 10:22:28
<?php
error_reporting(0);
header('Content-Type: text/html; charset=utf-8');

$s=<<<HTML
<block name="content">我是一层</block>
<block name="content">我是二层</block>
<block name="content">
<div class="test">我是三层div</div>
<block name="style">
<style>
img {
-webkit-transform: scale(1) rotate(0) translate3d(0,0,0);
transform: scale(1) rotate(0) translate3d(0,0,0);
}
#editor-wrap{padding: 10px; display: flex; justify-content: space-between; overflow: hidden}
#editor-tool{ flex-shrink:0; width: 30px; height: 72px; display: flex; justify-content: space-between; align-items: center; flex-direction: column; overflow: hidden}
#editor-tool a{ width: 30px; height: 30px; display: block; cursor: pointer; overflow: hidden}
#editor-tool .iconfont{height: 30px; line-height: 34px; color: #666; font-size: 30px;}
#editor-text{ -webkit-user-select: auto; flex-grow: 1; margin-left: 10px; border:1px solid #ccc; height: 60px; padding: 5px; line-height:30px; word-wrap:break-word; overflow-x: hidden; overflow-y: auto}
#editor-text img{vertical-align: middle}
#editor-emoji{height: 68px; padding: 10px 5px; border-top: 1px solid #eee; position: relative; overflow: hidden}
#editor-emoji-box ul{ display: none; margin-top: -8px; justify-content: flex-start; align-items: center; flex-wrap: wrap;}
#editor-emoji-box li{ flex-basis: 10%; flex-shrink: 0; height: 30px; margin-top: 8px; display: flex; justify-content: center; align-items: center;}
#editor-emoji-box img{ background-size: 50%}
#editor-emoji-btn{ position: absolute; right: 10px; bottom: 10px; display: flex; height: 30px; line-height: 30px; text-align: center; font-weight: bold;}
</style>
</block>
<div>11111111</div>
</block>
<block name="content">我是四层</block>
<block name="content">我是五层</block>
HTML;

$p = '#<block\sname=[\'"](.+?)[\'"][^>]*>([^<>])*</block>#eis';
preg_match_all($p,$s,$m);
die(print_r($m));




匹配的不是这个位置的结束标签,
...全文
126 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2017-05-16
  • 打赏
  • 举报
回复
要用 正则平衡组 不过 html 有不需要封闭的标签 所以最好是使用现成的工具类:simple_html_dom、phpQuery

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧