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?