|
Posted by Frank Arensmeier on 04/05/05 13:17
You should describe more specific what is going wrong with your script.
What does the script output? Maybe you should post a vardump as well.
/frank
2005-04-05 kl. 11.07 skrev Jason:
> Could someone tell me what I did wrong with this script. It should
> read the page
> http://www.mto.gov.on.ca/english/traveller/conditions/rdclosure.htm
> and only read between the 2 words in the script. And email any new
> stuff to the email address in the script. What did I do wrong that is
> causing this script to fail?
>
>
>
> <?
> #
> -----------------------------------------------------------------------
> -----------
> # Configuration
>
> # Directory on the remote server. Be sure to include leading and
> trailing slashes!
> $remotedir = "/english/traveller/conditions/";
>
> # File on the remote server. No slashes!
> $remotefile = "rdclosure.htm";
>
> # Keyword to check for in response.
> $keyword = "Closed";
>
> # Remote server address.
> $remoteserver = "www.mto.gov.on.ca";
>
> # E-mail recipient(s). Separate each address with a comma and a space.
> $emailrecip = "webmaster@weatherserver.net";
>
> # E-mail subject line.
> $emailsubject = "MTO - TEST" . date(' (G:i:s)');
>
> # E-mail From name.
> $emailfromname = "WxServer Roads";
>
> # E-mail From address.
> $emailfromaddr = "WxServer@weatherserver.net";
>
> # End Configuration
> #
> -----------------------------------------------------------------------
> -----------
>
> # Format the page for easy viewing.
> Header( "Content-type: text/html");
>
> # Setup the request.
> $header .= "GET " . $remotedir . $remotefile . " HTTP/1.0\r\n";
> $header .= "Host: " . $remoteserver . "\r\n";
> $header .= "User-Agent: Downloader\r\n\r\n";
> $fp = fsockopen ($remoteserver, 80, $errno, $errstr, 30);
>
>
>
>
> # Do the request.
> fputs ($fp, $header . $req) or die("Can't access the site!");
>
> while (!feof($fp)) {
> $res .= fgets ($fp, 128);
> }
>
> # Strip off the header info.
> $res = preg_replace("/<[^>]+>/", "", $res);
> $res = preg_replace("/Last
> Updated\:\s+?\d\d\d\d-\d\d-\d\d\s+?\d\d\:\d\d/", "", $res);
> $res = preg_replace("/ /", "", $res);
> $headerend = strpos($res,"\r\n\r\n");
>
> if (is_bool($res)) {
> $result = $res;
> }
> else {
> $result = substr($res,$headerend+4,strlen($res) - ($headerend+4));
> }
>
> fclose ($fp);
>
> # Start and end tags
> $startstr = "Highways";
> $endstr = "This";
>
> # Find start and end positions
> $startpos = strpos($result, $startstr) + strlen($startstr);
> $endpos = strpos($result, $endstr, $startpos);
>
> # Get string between 2 tags
> $result = substr($result, $startpos, $endpos-$startpos);
> echo ($new_res);
>
> # Check for keyword.
> if (!stristr($result, $keyword)) die("ERROR Code Word Not Found");
>
> # Read the file containing the last response.
> $filename = $remotefile . '.txt';
> $fp = fopen($filename, "r");
> $contents = fread($fp, filesize($filename));
> fclose($fp);
>
>
>
>
> # Check for changes.
> if ($contents == $new_res) {
> # There has not been a change.
> echo ("No Updates\r\n");
> } else {
> # There has been a change.
> echo ("**UPDATES DETECTED**\r\n");
>
> # Write the new file.
> $filename = $remotefile . '.txt';
> $fp = fopen($filename, "w");
> $write = fputs($fp, $result);
> fclose($fp);
>
> # Send the e-mail.
> $recipient = $emailrecip;
> $subject = $emailsubject;
> $body_of_email = $result;
>
> $header = 'From: "' . $emailfromname . '" <' . $emailfromaddr . '>';
>
> mail ($recipient, $subject, $body_of_email, $header);
>
> echo ("E-mail sent.");
>
> }
> ?>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
[Back to original message]
|