I am using the following code:
<?php $stock = $_GET[s]; //returns stock ticker symbol eg GOOG or YHOO $first = $stock[0]; $url = 'http://biz.yahoo.com/research/earncal/'.$first.'/'.$stock.'.html'; $data = file_get_contents($url); $r_header = '/Prev. Week(.+?)Next Week/'; $r_date = '/\<b\>(.+?)\<\/b\>/'; preg_match($r_header,$data,$header); preg_match($r_date, $header[1], $date); echo $date[1]; ?>
I’ve checked the regular expressions here and they appear to be valid. If I check just $url or $data they come out correctly and if I print $data and check the source the code that I’m looking for to use in the regex is in there. If you’re interested in checking anything, an example of a proper URL would be http://biz.yahoo.com/research/earncal/g/goog.html
I’ve tried everything I could think of, including both var_dump($header) and var_dump($date), both of which return empty arrays.
I have been able to create other regular expressions that works. For instance, the following correctly returns ‘Earnings’:
$r_header = '/Company (.+?) Calendar/'; preg_match($r_header,$data,$header); echo $header[1];
I am going nuts trying to figure out why this isn’t working. Any help would be awesome. Thanks.
Problem is that the HTML has newlines in it, which you need to incorporate with the s regex modifier, as below