Let's say I have this code, adapted from Adam Backstrom's answer to a previous question:
$term = 'example'; // word I need to replace
$replacement = '<strong>example</strong>'; // this will replace the $term
$d = new DOMDocument;
@$d->loadHTML($body); // specifically, drupal's $node->content['body']['#value'] in hook_nodeapi when $op='view'
$x = new DOMXPath($d);
$t = $x->evaluate("//text()");
foreach($t as $text) {
if( $text->parentNode->tagName != "a" ) {
$text->nodeValue = str_replace($term, $replacement, $text->nodeValue);
}
but when I output via $d->saveHTML()
I get a lot of ASCII characters and the tags are visible (HTML not rendered), I have also tried $d = new DOMDocument('1.0', 'Windows-1251')
to no avail...
Anyone?