2

I have the following code in PHP

$ch = curl_init("http://blog.com");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);      
curl_close($ch);
echo $output;

I am trying to import the block of code in between <div id="content"> and </div> I would like to know the best way of extracting this code.

Olimpiu POP
  • 5,001
  • 4
  • 34
  • 49
jeffreynolte
  • 3,749
  • 11
  • 41
  • 64

2 Answers2

6

DOM would be the best way. Here's a detailed documentation: http://php.net/manual/en/book.dom.php

Ruel
  • 15,438
  • 7
  • 38
  • 49
1

Using curl, the $output will be an String, so create a DOM using it:

$html = str_get_html($content);

Than, get the content:

$content = $html->find('#content');

raittes
  • 5,271
  • 3
  • 30
  • 27
  • thanks for your answer, but its not working in mine, when i try to pass string in str_get_html it will give me so many code – hio Jul 27 '21 at 17:28