I’m using simple_html_dom and when I get to the file_get_contents line, I get a null response. The URL is correct and this was working yesterday but not today. the code is as follows:
$sym = $symbol;
$yahooURL="https://finance.yahoo.com/quote/$sym/history?p=$sym";
//get stock name
$data = file_get_contents($yahooURL);
//at this stage $data is returning empty
$title = preg_match('/<title[^>]*>(.*?)</title>/ims', $data, $matches) ? $matches[1] : null;
$title = preg_replace('/[[a-zA-Z0-9. ]* | /','',$title);
$title = preg_replace('/ Stock - Yahoo Finance/','',$title);
$name = $title;
//get price data - use simple_html_dom.php
$body=file_get_html($yahooURL);
if (!empty($body)) {
$tables = $body->find('table');
$dom = new DOMDocument();
$elements[] = null;
$dom->loadHtml($tables[0]);
$x = new DOMXpath($dom);
...
allow_url_fopen is On
Any suggestions?
I’ve checked the URL is correct. I’ve checked the $data file which comes out as blank. The $sym is correct each time.I can’t think of anything else to try.