PHP DOMElement, replacing text of a node
        Posted  
        
            by 
                waitinforatrain
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by waitinforatrain
        
        
        
        Published on 2011-01-08T21:33:22Z
        Indexed on 
            2011/01/08
            21:53 UTC
        
        
        Read the original article
        Hit count: 303
        
I have a HTML node like so:
<b>Bold text</b>
A variable $el contains a DOMElement reference to the text of that HTML node ("Bold text"), got from the XPath expression //b/text()
I want to change the element to
<b><span>Bold Text</span></b>
So I tried:
$span = $doc->createElement('span', "Bold Text");
$el->parentNode->replaceChild($span,, $el)
which fails because parentNode is null.
So, as a test, I tried: $el->insertBefore($span, $el);
which throws no errors but produces no change in the output.
Any thoughts?
© Stack Overflow or respective owner