PHPBuilder - Creating a Printer Version Grab Method Page 7



RSS Twitter
Articles Html

Creating a Printer Version Grab Method - Page 7

by: Jim Fletcher
|
April 1, 2004

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.

<?php 
if ($resultb[1]==’’) {
?>
First we grab the entire webpage and store in variable $rf.

<?php 
$file 
fopen("$url""r");
$rf fread($file20000);
fclose($file);
?>
Next we parse out the printable content using the tags defined in the 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.

<?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.

<?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);
?>

« Previous Page
1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
9
|
10
Next Page »

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Jim Fletcher

Comment:



Comment:

(Maximum characters: 1200). You have characters left.