表达式似乎没有错。我在几个编辑器中将它与示例HTML相匹配。但是一旦我将它插入preg_match_all,我就没有结果。
有什么想法吗?
$regex_lists = '~<ul.*?>.+?</ul>~m';
preg_match_all($regex_lists, $html, $lists);
var_dump($lists); //empty array
示例HTML
<ul type="disc">
<br><li class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin- top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list .5in;">
<span style='font-family: "Arial","sans-serif"; font-size: 12pt; mso-fareast-font- family: "Times New Roman";'>Maintain complete knowledge of and comply with all departmental policies/service procedures/standards. <p></p></span>
<br>
</li>
<li class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list .5in;">
<span style='font-family: "Arial","sans-serif"; font-size: 12pt; mso-fareast-font- family: "Times New Roman";'>Maintain complete knowledge of correct maintenance and use of equipment. Use equipment only as intended. <p></p></span>
<br>
</li>
</ul>
答案 0 :(得分:2)
由于你的输入也有换行符,你需要s
(DOTALL)标志来使点匹配换行:
$regex_lists = '~<ul.*?>.+?</ul>~is';
OR
$regex_lists = '~<ul[^>]*>.+?</ul>~is';
PS:您的正则表达式中也不需要m
标记。