php - DOMDocument cannot parse curl response

I'm having trouble with this. I'm trying to get all the div tag but it's not returning any, this is the exact code and domain
<?php
$url = 'jwdpit.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$response = curl_exec($ch);
curl_close($ch);
$dom = new \DOMDocument();
$dom->loadHTML($response);
$table = $dom->getElementsByTagName('div');
print_r($table);
this is the output of print
DOMNodeList Object ( [length] => 0 )
Answer
Solution:
You need to include theCURLOPT_RETURNTRANSFER
option to return the value ofcurl_exec
instead of outputting it directly:
<?php
$url = 'jwdpit.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //added curl option
$response = curl_exec($ch);
curl_close($ch);
$dom = new \DOMDocument();
$dom->loadHTML($response);
$table = $dom->getElementsByTagName('div');
print_r($table); //DOMNodeList Object ( [length] => 16 )
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: ftp_put(): can't open that file: no such file or directory
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.