Skip to content Skip to sidebar Skip to footer

Php Xpath. How To Return String With Html Tags?

Message bold, strike

Solution 1:

I can do it using SimpleXML really quickly (if it's okay for you to switch from DOMDocument and DOMXPath, probably you will go with my solution):

$html = '
<html><body><div>
        Message <b>bold</b>, <s>strike</s></div><div><spanclass="how"><ahref="link"title="text">Link</a>, <b> BOLD </b></span></div></body></html>
    ';
    $xml = simplexml_load_string($html);
    $arr = $xml->xpath('//div/*');
    foreach ($arr as $x) {
      echo $x->asXML();
    }

Solution 2:

$dom = new DOMDocument;
foreach($messagesas$message)
{
    echo$dom->saveHTML($message); 
}

Use saveHTML()

Post a Comment for "Php Xpath. How To Return String With Html Tags?"