Why doesn't a PHP regex return an array?
My code is supposed to return an array containing a weather summary, but does not.
How can I make this work?
This is part of a course I'm taking onUdemy.com
; my code exactly matches my instructor's, but doesn't return the same results.
I didn't find any syntax errors so there is something else that I'm either missing or nescient of..
$contents=file_get_contents("http://www.weather-forecast.com/locations/San-Francisco/forecasts/latest");
preg_match('3 Day Weather Forecast Summary:<\/b><span class="phrase">(.*?)</s', $contents, $matches);
print_r($matches);
Answer
Solution:
You have to add some delimeter around your regex to seperate it from (possible) modifiers. You could use any char you want - ie
/
- but as you use this chars inside your regex it would maybe be easier to use something different like the tilde~
Just tested your regex and it seems, the html of the page doesn't match your expression. I slightly modified it as follows: