1

i want to extract html inside <p class="js-swt-text" without simplehtmldom

bellow is the working example i did with simplehtmldom:

<?php

include('simple_html_dom.php');
$html = file_get_html("http://blabla.com");
foreach($html->find('.js-swt-text') as $ret) {
    echo $ret;
}

?>

please help me to do with domdocument

<?php
$html = file_get_contents("http://blabla.com");

and echo html from every <p class="js-swt-text"

Kevin
  • 41,694
  • 12
  • 53
  • 70
uyrxe
  • 27
  • 5

1 Answers1

0

You can use:

$html = file_get_contents("http://blabla.com");
$dom = new DomDocument();
$dom->loadHtml($html);
$xpath = new DomXpath($dom);
$items = $xpath->query('//p[@class="js-swt-text"]');
foreach ($items as $item) {
   echo $item->textContent . "\n";
}
Davide Pastore
  • 8,678
  • 10
  • 39
  • 53