php - Simple HTML DOM Parser - Get all plaintex rather than text of certain element -
i tried solutions posted on question. although similar question, it's solutions aren't working me.
i trying plain text outside of <b>
, should inside <div id="maindiv>
.
<div id=maindiv> <b>i don't want text</b> want text </div>
$part object contains <div id="maindiv">
. tried this:
$part->find('!b')->innertext;
the code above not working. when tried this
$part->plaintext;
it returned of plain text
i don't want text want text
i read official documentation, didn't find resolve this:
query:
$selector->query('//div[@id="maindiv"]/text()[2]')
explanation:
// - selects nodes regardless of position in tree div - selects elements node name 'div' [@id="maindiv"] - selects divs having attribute id="maindiv" / - sets focus div element text() - selects text elements [2] - selects second text element (the first whitespace) note! actual position of text element may depend on preservewhitespace setting. manual: http://www.php.net/manual/de/class.domdocument.php#domdocument.props.preservewhitespace
example:
$html = <<<eof <div id="maindiv"> <b>i dont want text</b> want text </div> eof; $doc = new domdocument(); $doc->loadhtml($html); $selector = new domxpath($doc); $node = $selector->query('//div[@id="maindiv"]/text()[2]')->item(0); echo trim($node->nodevalue); // want text
Comments
Post a Comment