<code><br>$content = '<p> 这里是帖子的内容。</p><p> </p><p> <span>这里是帖子的其他内容</span></p><pre class="prettyprint linenums">$user = $this->session->get('auth'); $baa_id=(int)$_POST['baa_id']; $time = date('Y-m-d H:i:s');
这里是帖子的其他内容
‘;preg_match_all(‘#
]*>([^(?:)]*)
#’,$content,$matches);print_r($matches);
匹配的结果:
<code>Array</code><code>( [0] => Array ( [0] => <p> 这里是帖子的内容。</p> ) [1] => Array ( [0] => 这里是帖子的内容。 ))</code>
为什么p标签之间有img span等其他标签的内容不能被匹配呢?
回复内容:
<code><br>$content = '<p> 这里是<em>8本文来源gao.dai.ma.com搞@代*码(网$</em><pre>搞代gaodaima码
帖子的内容。
这里是帖子的其他内容
$user = $this->session->get('auth'); $baa_id=(int)$_POST['baa_id']; $time = date('Y-m-d H:i:s');
这里是帖子的其他内容
‘;preg_match_all(‘#
]*>([^(?:)]*)
#’,$content,$matches);print_r($matches);
匹配的结果:
<code>Array</code><code>( [0] => Array ( [0] => <p> 这里是帖子的内容。</p> ) [1] => Array ( [0] => 这里是帖子的内容。 ))</code>
为什么p标签之间有img span等其他标签的内容不能被匹配呢?
已更新,preg_match_all('#
]*)>([\s\S]*?)
#',$content,$matches);
这是完整的写法,你的问题在于你错误的以为[^(?:)]
代表的是除<p
>或者
标签以外的匹配。实际上[^(?:)]
等同于[^?:]
这样看就明白了吧
不用正则,xpath
搞定