Retrieve webpage content if not in cache
Here we will check to see if we successfully retrieved any content from
the cache. If the cache was empty or expired for this URL, we will go
grab the webpage.
the cache. If the cache was empty or expired for this URL, we will go
grab the webpage.
<?php
if ($resultb[1]==????) {
?>
First we grab the entire webpage and store in variable $rf.
<?php
$file = fopen("$url", "r");
$rf = fread($file, 20000);
fclose($file);
?>
Next we parse out the printable content using the tags defined in the
options above.
options above.
<?php
$grab = eregi("$GrabStart(.*)$GrabEnd", $rf, $printing);
?>
Next we delete any content chosen to be excluded. The printable
content is now ready and stored in variable $showme.
content is now ready and stored in variable $showme.
<?php
$showme = eregi_replace("$ExcludeStart[^>.]*$ExcludeEnd","",$printing[1]);
?>
Next we parse out the page title, but only if a title has not been sent
to the script via a variable.
to the script via a variable.
<?php
if (!$title) {
$grab = eregi("$TitleStart(.*)$TitleEnd", $rf, $thetitle);
$title = $thetitle[1];
} #end if no title
?>
Add grabbed data to MySQL cache. First delete any old cached data.
<?php
$sql = "DELETE FROM cache where url='$cacheurl'";
$resulta = mysql_query($sql);
?>
Next Create the new data??s timestamp.
<?php
$date=time();
?>
Next format the new data for the database.
<?php
$titleb = mysql_escape_string($title);
$contentb = mysql_escape_string($showme);
?>