PHP Classes

File: examples/preg_match.php

Recommend this page to a friend!
  Classes of Christian Vigh   PHP Search Large Files   examples/preg_match.php   Download  
File: examples/preg_match.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Search Large Files
Search large files that would not fit in memory
Author: By
Last change: Updated examples according to API changes
Date: 8 years ago
Size: 787 bytes
 

Contents

Class file image Download
<?php
   
include ( '../SearchableFile.phpclass' ) ;
   
$file = 'verybigfile.rtf' ;
   
$re = '/\\\\pict/' ;

   
$t1 = microtime ( true ) ;
   
   
$sf = new SearchableFile ( ) ;
   
$sf -> Open ( $file ) ;
   
$offset = 0 ;
   
$status1 = $sf -> pcre_match ( $re, $matches1, PREG_OFFSET_CAPTURE, $offset ) ;
   
$count1 = count ( $matches1 ) ;
   
   
$t2 = microtime ( true ) ;
   
   
$contents = file_get_contents ( $file ) ;
   
$offset = 0 ;
   
$status2 = preg_match ( $re, $contents, $matches2, PREG_OFFSET_CAPTURE, $offset ) ;
   
$count2 = count ( $matches1 ) ;

   
$t3 = microtime ( true ) ;
   
    echo
"Elapsed (SearchableFile) : " . round ( $t2 - $t1, 3 ) . " (count = $count1)\n" ;
    echo
"Elapsed (preg_match) : " . round ( $t3 - $t2, 3 ) . " (count = $count2)\n" ;