例子:
$html = '<h2></h2>
<p>date</p>
<ul></ul>
<iframe></iframe>
<p>apple</p>
<p>banana</p>
<p>grape</p>
<ul></ul>';
if (preg_match_all('~<p>(?P<paragraphs>.*?)</p>~is', $html, $matches)) {
print_r($matches['paragraphs']);
}
结果:
Array
(
[0] => date
[1] => apple
[2] => banana
[3] => grape
)
PS
“聪明”投反对票的人,你能评论一下你为什么投反对票吗?:)))))))))))))))
投反对票的两个人的PPS
特别版:
$document = new DOMDocument();
$document->loadHTML($html);
$paragraphs = $document->getElementsByTagName('p');
$result = array();
foreach ($paragraphs as $paragraph) {
$result[] = $paragraph->nodeValue;
}
print_r($result);