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>
        <span class="how">
            <a href="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:


Post a Comment for "PHP XPath. How To Return String With Html Tags?"