$content = '这里是帖子的内容。
@@##@@
这里是帖子的其他内容
$user = $this->session->get('auth'); $baa_id=(int)$_POST['baa_id']; $time = date('Y-m-d H:i:s');这里是帖子的其他内容
'; preg_match_all('#]*>([^(?:?p>)]*)
#',$content,$matches); print_r($matches);匹配的结果:
Array( [0] => Array ( [0] =>这里是帖子的内容。
) [1] => Array ( [0] => 这里是帖子的内容。 ) )为什么p标签之间有img span等其他标签的内容不能被匹配呢?
回复内容:
$content = '这里是帖子的内容。
@@##@@
这里是帖子的其他内容
$user = $this->session->get('auth'); $baa_id=(int)$_POST['baa_id']; $time = date('Y-m-d H:i:s');这里是帖子的其他内容
'; preg_match_all('#]*>([^(?:?p>)]*)
#',$content,$matches); print_r($matches);匹配的结果:
Array( [0] => Array ( [0] =>这里是帖子的内容。
) [1] => Array ( [0] => 这里是帖子的内容。 ) )为什么p标签之间有img span等其他标签的内容不能被匹配呢?
已更新,
preg_match_all('#]*)>([\s\S]*?)
立即学习“PHP免费学习笔记(深入)”;
#',$content,$matches);
这是完整的写法,你的问题在于你错误的以为[^(?:?p>)]代表的是除标签以外的匹配。实际上>或者
[^(?:?p>)]等同于[^?:?p>]这样看就明白了吧
不用正则,
xpath搞定![]()












