<?php $html = 'This should be extracted <p>I do not want this</p> This should also be extracted <a>This may appear after other tags and I do not want this</a>'; $doc = new DOMDocument(); $doc->loadHTML("<div>$html</div>", LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED); $xpath = new DOMXPath($doc); $texts = array(); foreach ($xpath->query('/div/text()') as $text) { $texts[] = $text->nodeValue; } print_r($texts);
You have javascript disabled. You will not be able to edit any code.