entry[0]; if (file_exists($lastfile)) { $f = fopen($lastfile, 'r'); $last = (int) fread($f, 1024); fclose($f); } else { $last = 0; } $parts = explode('/', $item->id); $current = (int) $parts[3]; if ($current > $last) { $date = date("Y-m-d", strtotime($item->updated)); preg_match("#title=\"(.+)\"#iU", $item->summary, $t); // To send HTML mail, the Content-type header must be set //$headers = 'MIME-Version: 1.0' . "\r\n"; $headers = 'Content-type: text/html; charset=UTF-8' . "\r\n"; $headers .= 'From: '. $from . "\r\n"; $subject = "xkcd {$date}: {$item->title}"; $punchline = $t[1]; $msg = "
{$punchline}
\n"; mail($mail, $subject, $msg, $headers); $f = fopen($lastfile, 'w'); fwrite($f, $current); fclose($f); echo "New last is $current (was $last)\n"; } else { echo "No new XKCD: last=$last current=$current\n"; } ?>