Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php preg_match_所有未找到匹配项_Php_Regex_Preg Match All - Fatal编程技术网

Php preg_match_所有未找到匹配项

Php preg_match_所有未找到匹配项,php,regex,preg-match-all,Php,Regex,Preg Match All,这个表达似乎没有什么问题。我已经在几个编辑器中将其与示例HTML进行了匹配。但一旦我把它插入preg_match_all,我就没有结果了 有什么想法吗 $regex_lists = '~<ul.*?>.+?</ul>~m'; preg_match_all($regex_lists, $html, $lists); var_dump($lists); //empty array $regex_list='~.+?~m'; preg_match_all($regex_li

这个表达似乎没有什么问题。我已经在几个编辑器中将其与示例HTML进行了匹配。但一旦我把它插入preg_match_all,我就没有结果了

有什么想法吗

$regex_lists = '~<ul.*?>.+?</ul>~m';
preg_match_all($regex_lists, $html, $lists);

var_dump($lists); //empty array
$regex_list='~.+?~m';
preg_match_all($regex_list,$html,$list);
var_dump($列表)//空数组
示例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>

  • 完全了解并遵守所有部门政策/服务程序/标准


  • 掌握正确维护和使用设备的完整知识。仅按预期使用设备



由于您的输入也有换行符,您需要使用
s
(DOTALL)标志使点匹配换行符:

$regex_lists = '~<ul.*?>.+?</ul>~is';
$regex_list='~.+?~is';

$regex_list='~]*>。+?~is';

PS:您的正则表达式中也不需要
m
标志。

您可能需要了解这一点:谢谢,我主要使用DOMDoc、SimpleXML和XPATH库。在本例中,我使用正则表达式是因为内容和格式不一致。我使用正则表达式根据特定的表达式将DOM分解成若干部分,这将留下未关闭的标记。不确定这是否是最佳实践,但它很快,而且根据anubhava的建议,我认为我已经完成了90%的任务。只要您知道这些选项,您就可以选择最适合您特定用例的选项:-)太好了!就这样。我用的是m修饰符,认为这是“点匹配新线”修饰符。谢谢你给我指出正确的用法。
$regex_lists = '~<ul[^>]*>.+?</ul>~is';