1
大家好,我正在使用正则表达式,并且在内容中有空格或换行符时无法使其正常工作。PHP和preg_match_all的正则表达式问题
$content = "<dt><span>Name:</span></dt>
<dd>
John
</dd>
<dt><span>Age:</span></dt>
<dd>
40
</dd>
<dt><span>Sex:</span></dt>
<dd>
Male
</dd>";
我使用的正则表达式是
preg_match_all('/<dt><span>(.*)<\/span><\/dt><dd>(.*)<\/dd>/',$content, $output);
你应该为此使用DOM解析器,而不是正则表达式。 – 2013-03-20 18:34:24
http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags#answer-1732454 – webbiedave 2013-03-20 18:36:47
你可以在标签之间添加'[\ h \ v] *'该模式 – 2013-03-20 18:37:40