How to return 'object', not string or html using cURL?
There's str_get_html()
function available in SimpleHTMLDOM that you can use in order to load up the curl
return values.
Just modofy it accordingly:
function file_get_html_using_CuRL($url) { if (!function_exists('curl_init')){ die('CURL is not installed!'); } $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); $output = str_get_html($output); curl_close($ch); return $output;}
This returns a SimpleHTMLDOM object in which you can now chain up methods of your liking like ->find()
, etc. then make your necessary logic.
Note: Of course load up the SimpleHTMLDOM library first.