Aşağıdaki foreachta, ben anahtar kelime için $ node.TextContent ayrıştırmak ve çevresinde kalın etiketi sarmak gerekir. Bu DOM ile mümkün mü? Nasıl?
$myContent ="<h1>This word should not be replaced: TEST</h1>. But this one should be replaced: test";
$dom = new DOMDocument;
$dom->loadHTML(strtolower($myContent));
$xPath = new DOMXPath($dom);
foreach($xPath->query("//text()[contains(.,'test') and not(ancestor::h1)]") as $node)
{
/*need to do a replace on each occurrence of the word "test"
in $node->textContent here so that it becomes <b>test</b>. How? */
}
echo $dom->saveHTML
vermelidir:
<h1>This word should not be replaced: TEST</h1>.
But this one should be replaced: <b>test</b>"