I've got a tiny script that is failing on me, and i'm not sure why. Getting your run of the mill: <BR><B>Parse error</B>: syntax error, unexpected T_STRING in <B>/home/theriv00/domains/ccddd.com/public_html/cacheparse.php</B> on line <B>4</B><BR> Here's the code: <?php $n= $_GET['n']; $data = file_get_contents('http://webcache.googleusercontent.com/search?sourceid=navclient&ie=UTF-8&q=cache=http://www.'.$n.'); $regex = '/snapshot of the page as it appeared on (.+?) GMT/'; preg_match($regex,$data,$match); echo $match[1]; ?> Why would the script be failing on line 4? (the regex entry). Something tells me it's the line above with the file_get_contents call. I have a program that is calling this script and is passing a domain name ($n) to the file_get_contents) call. The tricky part is that i'm having the script parse google but passing the domain name as the variable. Any ideas where I'm falling apart? http://www.mysite.com/cacheparser.php?n=domain.com
Use it as this : $data = file_get_contents('http://webcache.googleusercontent.com/search?sourceid=navclient&ie=UTF-8&q=cache=http://www.'.$n);
//$n= $_GET['n']; $n = "yahoo.com"; // or could be http://www.yahoo.com either way is fine $data = file_get_contents("http://webcache.googleusercontent.com/search?q=cache:$n"); //echo $data; $regex = '/snapshot of the page as it appeared on (.+?) GMT/'; preg_match($regex,$data,$match); echo $match[1]; // 2 Dec 2010 01:42:33; PHP: EDIT: or cURL //$n= $_GET['n']; $n = "yahoo.com"; // or could be http://www.yahoo.com either way is fine $url = "http://webcache.googleusercontent.com/search?q=cache:$n"; $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, '5'); $data = curl_exec($ch); curl_close($ch); //echo $data; $regex = '/snapshot of the page as it appeared on (.+?) GMT/'; preg_match($regex,$data,$match); echo $match[1]; // 2 Dec 2010 01:42:33 PHP: On different servers you might get different date formats, so results could be Dec 2, 2010 01:42:33 if that's a problem lets us know.
voda, thanks for the help again. It's not so much the end result, it's the in between that's teaching me. Thanks