2
如何用symfony dom履带提取未标记的元素。例如在下面的示例html中,我想提取Hello World
。用symfony dom履带提取未标记的元素
<strong>title</strong>Hello World<strong>Sub-Title</strong><div>This is just stuff</div>
如何用symfony dom履带提取未标记的元素。例如在下面的示例html中,我想提取Hello World
。用symfony dom履带提取未标记的元素
<strong>title</strong>Hello World<strong>Sub-Title</strong><div>This is just stuff</div>
您可以用PHP DOM做到这一点很容易;)
$dom = new DOMDocument();
$dom->loadHTML('<strong>title</strong>Hello World<strong>Sub-Title</strong><div>This is just stuff</div>');
$xpath = new DOMXPath($dom);
// use the fact that PHP DOM wraps everything into the body and get the text()
$entries = $xpath->query('//body/text()');
foreach ($entries as $entry) {
echo $entry->nodeValue;
}