I'm trying to insert tooltips into a generated html string. I am loading the string into a DOMDocument object to do this to insure that no tags are modified. The problem I am having is that when I get to the DOMText object and replace the text with a new node containing a span and continue, the script descends into the span and creates tooltips inside tooltips (it seems to only go one level deep). Heres how I'm doing this:
- Code: Select all
private function insertTips(&$node, array &$tooltips){
if(!$node->hasChildNodes()){
if($node->nodeType != XML_TEXT_NODE){
return;
}
$value = $node->nodeValue;
if(!empty($value)){
$temp = $node->ownerDocument->createDocumentFragment();
@$temp->appendXML(preg_replace(array_keys($tooltips), array_values($tooltips), $value));
$node->parentNode->replaceChild($temp, $node);
}
}
else{
// Create static array of references to child nodes
$nodes = array();
foreach($node->childNodes AS $childNode){
$nodes[] = $childNode;
}
foreach($nodes AS $childNode){
$this->insertTips($childNode, $tooltips);
}
}
}
I pass the 'body' node of the html page into the method for to start. My confusion here is how does the script manage to enter the newly created span elements when the script should be continuing to a node further along in the file referenced in the static array I previously created.
Anyone see the problem in the script / faced this obstacle before?
-nomad311

