Newbie PHP script not working, syntax help

I’ve been trying for the past several days to get going with arduino + xport direct + webserver hosting a php program to all talk. I am reading “making things talk” and working on the chapter 4 script for scraping data from a website and the code in the example doesn’t work. I’ve been trying to modify it but i’m stuck.

The website they reference in thier tutorial doesn’t look the same as thier screen shot of it, so i found an easier one to scan through, and I changed some variable names to make the new website data jive with what i’m doing. I have been getting the same problems every time I run it, both for the un-modified version directly out of the book, and for my updated version.

<?php
$readWeather = 0;  
$weather = -1;  
$url =  
      'http://www.timeanddate.com/worldclock/city.html?n=179';
$filePath = fopen($url, "r");
while (!feof($filePath))
{
      $line = fgetss($filePath, 4096);

      if (preg_match('Description:', $line))
      {
            if($weather == -1)
            {
                  $readWeather = 1;
                }
      }

        if ($readWeather == 1)
      {
            $weather = trim($line);
            echo "<Currently $weather>";
            $readWeather = 0;
      }

}
fclose($filePath);
?>

When I upload and run the .php script, I always get these two responses:

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/myusername/mydomain.com/arduino/Scraper.php on line 7

Parse error: syntax error, unexpected T_VARIABLE in /home/myusername/mydomain.com/arduino/Scraper.php on line 8

Any suggestions?

What version of PHP are you using? I pasted your code in a new php file, and got different errors, using 5.3.3.

The errors I get point to preg_match not getting correct input. The preg_match function does regular expression pattern matching. "Description:" is not a regular expression.

I suspect it is something like this you are looking for

<?php
$url = "http://www.timeanddate.com/worldclock/city.html?n=179";

$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL, $url);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);

if (empty($buffer))
{
      print "Sorry, server seems to be offline";
}
else
{
      echo getBetween($buffer, "Description:</td><td colspan=3>", "</td>");
}


function getBetween($content,$start,$end)
{
      $a1 = strrpos($content,$start);
      $content = substr($content,$a1 + strlen($start));
      while($a2 = strrpos($content,$end))
      {
            $content = substr($content,0,$a2);
      }
      return $content;
} 
?>

This will return what is between “Description:” and “”

php version is 5.2.15 hosting via dreamhost.

Bid - i put what you wrote up and it works for me to get me started, thanks. I think i'm going to go out and get the o'rielly book so i can better understand whats going on with this stuff. The book I have leads me pretty blind. I'm new to network and web stuff... i'm more hardware minded. Thanks again