Search Webmaster Help and Solution

preg_match variables

I am using the following:

$content = file_get_contents(http://forecast.weather.gov/MapClick.php?lat=36.37870&lon=-86.45310&f6=1&mp=1);

preg_match(#<td align="left">Nashville</td>
<td align="left">(.*)</td>#, $content, $match);

$price = $match[1];

the above works, but I am now trying to use a variable intead of hard coding:

$city=Nashville;
$content = file_get_contents(http://forecast.weather.gov/MapClick.php?lat=36.37870&lon=-86.45310&f6=1&mp=1);

preg_match(#<td align="left">$city</td>
<td align="left">(.*)</td>#, $content, $match);

I have tried all kinds of combinations like /$city/, {$city}, but I cant get it to take my variable.

Please Help. been strugling for days on this one. I am using the following:

$content = file_get_contents(http://forecast.weather.gov/MapClick.php?lat=36.37870&lon=-86.45310&f6=1&mp=1);

preg_match(#<td align="left">Nashville</td>
<td align="left">(.*)</td>#, $content, $match);

$price = $match[1];

the above works, but I am now trying to use a variable intead of hard coding:

$city=Nashville;
$content = file_get_contents(http://forecast.weather.gov/MapClick.php?lat=36.37870&lon=-86.45310&f6=1&mp=1);

preg_match(#<td align="left">$city</td>
<td align="left">(.*)</td>#, $content, $match);

I have tried all kinds of combinations like /$city/, {$city}, but I cant get it to take my variable.

Please Help. been strugling for days on this one.

View Complete Thread with Replies

Related Items

Query failed: connection to localhost:3354 failed (errno=111, msg=Connection refused).