开发者

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
} 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜