PHP Classes

File: examples/multistrpos.php

Recommend this page to a friend!
  Classes of Christian Vigh   PHP Search Large Files   examples/multistrpos.php   Download  
File: examples/multistrpos.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: 634 bytes
 

Contents

Class file image Download
<?php
   
include ( '../SearchableFile.phpclass' ) ;
   
$file = 'verybigfile.rtf' ;
   
$t1 = microtime ( true ) ;

   
$sf = new SearchableFile ( ) ;
   
$sf -> Open ( $file ) ;
   
$pos = 0 ;
   
$search = [ '\\pict', '\\sv', '\\LTRPAR' ] ;
   
$pos1 = [] ;


    while ( (
$pos = $sf -> multistripos ( $search, $pos, $found_index, $found_string ) ) !== false )
    {
       
// echo "POS1 = $pos, STR = $found_string\n" ;
       
$pos1 [] = $pos ;

       
$pos += strlen ( $found_string ) ;
    }

   
$t2 = microtime ( true ) ;

    echo
"Total time : " . round ( $t2 - $t1, 3 ) . "\n" ;
    echo
count ( $pos1 ) . " occurrences found\n";