0

我有一个带有正则表达式的 php 代码,它在 li 标记内 p 标记的新行上失败。当我执行此代码时,它会从中删除</ul></li>

<?php
$data   =   "<h1>test</h1>
            <h2>test</h2>
            <p>This is not real text but just a test, This is not real text but just a test, This is not real text but just a test, This is not real text but just a test, This is not real text but just a test</p>
            <ul><li><p>This is not real text but just a test, This is not real text but just a test, This is not real text but just a test, This is not real text but just a test</p>
            </li></ul>
            <ul><li><p>This is not real text but just a test, This is not real text but just a test, This is not real text but just a test, This is not real text but just a test</p>
            </li></ul>";

$pattern    =   "#[\<ul\>\<li\>]*\<[p]*[h1]*[h2]*[h3]*\>(.+?)\</[p]*[h1]*[h2]*[h3]*\>[\</li\>\</ul\>]*#is";
preg_match_all($pattern, $data, $output);
var_dump($output);
?>

谁能帮我这个?

4

1 回答 1

0

我不完全确定您要达到的目标,但我认为纠正模式将是这样的:

#\s*(<ul><li>)?(\s*<(p|h1|h2|h3)>)*(.+?)(</(p|h1|h2|h3)>\s*)*(</li></ul>)?#is

编辑:纠正了一个错误

于 2012-07-04T12:26:56.663 回答