Location: PHPKode > scripts > Page Ripper > page-ripper/pageripper.class.php
<?php
 /*
 Date: 10-10-2006 9:11
 Author: B.Heesen (<a href="mailto:hide@address.com">hide@address.com</a>)
 Version: 0.2b
 © Cpyright 2006 De Bron Digital Solutions (<a href="http://www.dbds.nl/">http://www.dbds.nl</a>)
 */
 
# Usage:
# require("pageripper.class.php");
# $pr = new PageRip();
# $pr->getChunk($url,$start,$end,$repair_start,$repair_end,$error_msg);
class PageRip {
 
        var $url;
        var $formurl;
        var $postfields;
        var $start;
        var $end;
        var $repair_start;
        var $repair_end;
        var $error_msg;
        var $str_rep_1;
        var $str_rep_2;
        var $str_rep_3;
        var $str_rep_1_with;
        var $str_rep_2_with;
        var $str_rep_3_with;
 
        //get piece of page and "repair" start en end
        function getChunk($url,$start,$end,$repair_start,$repair_end,$error_msg){
      $ch = curl_init();
     curl_setopt ($ch, CURLOPT_URL, $url );
     curl_setopt ($ch, CURLOPT_HEADER, 0);
     curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
     $result = curl_exec ($ch) or die ("Couldn't connect to $url.");
     curl_close ($ch);
     $startposition = strpos($result,$start);
     if($startposition> 0){
       $endposition = strpos($result,$end, $startposition);
       //add enough chars to include the tag
       $endposition += strlen($end);
       $length = $endposition-$startposition;
       $result = substr($result,$startposition,$length);
      return $repair_start . $result . $repair_end;
     }else{
       return "<center>
<h3>".$error_msg."</h3>
</center>";
     }      
        }      
 
    //get piece of page after submitting a form
        function getChunkWithForm($formurl,$postfields,$url,$start,$end,$repair_start,$repair_end,$error_msg){
     $ch = curl_init();
     curl_setopt ($ch, CURLOPT_URL, $url );
     curl_setopt ($ch, CURLOPT_HEADER, 0);
     curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);   
     /* new */
     curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
     curl_setopt($ch, CURLOPT_URL,$formurl);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
     ob_start();      // prevent any output
     curl_exec ($ch); // execute the curl command
     ob_end_clean();  // stop preventing output
     curl_close ($ch);
     unset($ch);
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
     curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
     curl_setopt($ch, CURLOPT_URL,$url);
     $result = curl_exec ($ch) or die ("Couldn't connect to $url.");
     curl_close ($ch);
     $startposition = strpos($result,$start);
     if($startposition> 0){
      $endposition = strpos($result,$end, $startposition);
      //add enough chars to include the tag
      $endposition += strlen($end);
      $length = $endposition-$startposition;
      $result = substr($result,$startposition,$length);
      return $repair_start . $result . $repair_end;
     }else{
       return "<center>
<h3>".$error_msg."</h3>
</center>";
     }      
 
        }      
 
    //get piece of page and repair start en end and replace max 3 string
    function getChunkandReplace($url,$start,$end,$repair_start,$repair_end,$error_msg,$str_rep_1 = "",$str_rep_1_with = "",$str_rep_2 = "",$str_rep_2_with = "",$str_rep_3 = "",$str_rep_3_with = ""){
      $ch = curl_init();
     curl_setopt ($ch, CURLOPT_URL, $url );
     curl_setopt ($ch, CURLOPT_HEADER, 0);
     curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
     $result = curl_exec ($ch) or die ("Couldn't connect to $url.");
     curl_close ($ch);
     $startposition = strpos($result,$start);
     if($startposition> 0){
       $endposition = strpos($result,$end, $startposition);
       //add enough chars to include the tag
       $endposition += strlen($end);
       $length = $endposition-$startposition;
       $result = substr($result,$startposition,$length);
       if($str_rep_1 <> ""){
         $result = str_replace($str_rep_1,$str_rep_1_with,$result);
       }
       if($str_rep_2 <> ""){
         $result = str_replace($str_rep_2,$str_rep_2_with,$result);
       }
       if($str_rep_3 <> ""){
         $result = str_replace($str_rep_3,$str_rep_3_with,$result);
       }
 
      return $repair_start . $result . $repair_end;
     }else{
 
       return "<center>
<h3>".$error_msg."</h3>
</center>";
     }      
   
    }
    //get piece of page after submitting a form and repair start en end and replace max 3 string
    function getChunkandReplaceWithForm($formurl,$postfields,$url,$start,$end,$repair_start,$repair_end,$error_msg,$str_rep_1 = "",$str_rep_1_with = "",$str_rep_2 = "",$str_rep_2_with = "",$str_rep_3 = "",$str_rep_3_with = ""){
     $ch = curl_init();
     curl_setopt ($ch, CURLOPT_URL, $url );
     curl_setopt ($ch, CURLOPT_HEADER, 0);
     curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
     curl_setopt($ch, CURLOPT_URL,$formurl);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
     ob_start();      // prevent any output
     curl_exec ($ch); // execute the curl command
     ob_end_clean();  // stop preventing output
     curl_close ($ch);
     unset($ch);
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
     curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
     curl_setopt($ch, CURLOPT_URL,$url);
     $result = curl_exec ($ch) or die ("Couldn't connect to $url.");
     curl_close ($ch);
     $startposition = strpos($result,$start);
     if($startposition> 0){
      $endposition = strpos($result,$end, $startposition);
      //add enough chars to include the tag
      $endposition += strlen($end);
      $length = $endposition-$startposition;
      $result = substr($result,$startposition,$length);
      if($str_rep_1 <> ""){
       $result = str_replace($str_rep_1,$str_rep_1_with,$result);
      }
      if($str_rep_2 <> ""){
        $result = str_replace($str_rep_2,$str_rep_2_with,$result);
      }
      if($str_rep_3 <> ""){
        $result = str_replace($str_rep_3,$str_rep_3_with,$result);
      }
      return $repair_start . $result . $repair_end;
     }else{
      return "<center>
<h3>".$error_msg."</h3>
</center>";
     }
    }      
 
     
     
     
}
?> 

Return current item: Page Ripper