Search code examples
phpsnoopy

How get text between two closed tags Snoopy PHP


How can i retrieve the text between two tags with Snoopy PHP Example :

<html>
<body>
<h1> Test </h1>
</body>
</html>

in this example i want get "Test" thanks


Solution

  • Try this code it will give you the result

    <?php
     $doc =new DOMDocument();
     $doc->loadHTML("<html><body><h1>TEst</h1></body></html>");
     $xml=simplexml_import_dom($doc);
     $h1 = $xml->xpath('//h1');
     echo $h1[0];
    ?>