extract content between all paragraph tags
How do I extract only the content between all of the <p></p>
tags in a given string? I know preg开发者_如何学JAVA_match or regex but I spent hours already trying to put this stuff together. thought I'd just ask. simple question and a simple answer i hope. Thanks in advance. this would be in PHP, btw.
DOMDocument::loadHTML. Maybe not the fastest option, but should be simple.
Something like (it's been a while since I've actually written PHP...):
$doc = new DOMDocument();
$doc->loadHTML($string);
foreach($doc->getElementsByTagName('p') as $paragraph) {
// do something with $paragraph->textContent
}
精彩评论