Skip to main content.

Free PHP robot class

Setup
Set user agent
GetStatus
GetEverything
GetHeaders
GetUrls
GetHTML
GetTEXT
Example Code


Setup
First you need to download the class

First to use this class do this:
$robot = new Robot;
remeber what ever you replace $robot with that's what you need
to put a the start of each function like this:
$robot->FUNCTION();


Set user agent
To set your user agent you need to do this:
Agent = "test robot/1";


Get Status
GetStatus( [url] );
This returns the status of the url or returns false on error.


Get Everything
GetEverything( [url] );
This returns everything including headers from url or it returns
false on error.


Get Urls
GetUrls( [url] );
This returns an array of urls that start with http:// from url
or it returns false on error.


Get Headers
GetHeaders( [url] );
Returns the complete list of headers from url or returns false.


Get HTML
GetHTML( [url] );
Returns all the HTML from url or false on error.


Get TEXT
GetTEXT( [url] );
Returns all the text from url or returns false on error.


Example Code
<?php
//make robot
$robot = new Robot;
//set agent
$robot->Agent = "test robot/1";
//get the text from the url
$text = $robot->GetTEXT("http://www.free-php.org.uk/");
echo $text;
?>


<?php
//make robot
$robot = new Robot;
//set agent
$robot->Agent = "test robot/1";
//get the text from the url
$text = $robot->GetTEXT("http://www.free-php.org.uk/");
echo
$text;
?>


<?php
// Link checker
$url = "http://www.your-site.com/page-you-want-to-check-links-on.html";
$linkchecker = new Robot;
$linkchecker->Agent = "link checker/1";
$urls = $linkchecker->GetUrls( $url );
if(
$urls != false) {
   for(
$i=0;isset($urls[$i]);$i++ ) {
      print
"Checking: ".$urls[$i]." .....<br />\n";
      
$status = $linkchecker->GetStatus( $urls[$i] );
      if(
$status != false) {
         print
"".$status."<br /><br />\n";
      } else {
         print
"that url seems not to exist.\n";
      }
   }
} else {
   print
"Sorry the url you entered seems not to exist.";
}
?>



If you find any errors or have any ideas how to make this class
better, Or you need help with this class please email me at
admin@free-php.org.uk


Copyright © 2005 Sam J. Clarke.
All rights reserved.