WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : An efficient iterative and buffered text file reader
Categories : PHP, Classes and Objects, Filesystem, PHP Classes, Log Files Click here to Update Your Picture
Ioannis Cherouvim
Date : Mar 22nd 2005
Grade : 3 of 5 (graded 2 times)
Viewed : 9530
File : 4105.php
Images : No Images for this code example.
Search : More code by Ioannis Cherouvim
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?php

//***************************************************************
//** title  : An efficient iterative and buffered text file reader
//**
//** story  : I once wanted to write a web statistics
//**          generator based on parsing the entries of
//**          access.log of the Apache server. I used
//**          file() to get all the lines in an array.
//**          It worked. When I uploaded it on some server
//**          I got an out of memmory error from the server.
//**          Thats because the file was 18mb. I then
//**          wrote this class which loads the text file
//**          in chunks of 2048 bytes and has a method
//**          for returning one line at a time. A line
//**          is ended by a newline ('\n').
//**
//** author : Ioannis Cherouvim
//** e-mail : morales@hack.gr
//** date   : 2005-03-22
//*******************************************************

class Reader {
    var
$file;
    var
$filename;
    var
$filesize;
    var
$step = 2048;
    var
$buffer = "";
    var
$bytesRead = 0;
    var
$delimiter = "\n";

   
//instantiate reader
   
function Reader($filename) {
       
$this->filename = $filename;
    }

   
//open file
   
function open() {
       
$this->file = fopen ($this->filename, "r");
       
$this->filesize = filesize($this->filename);
    }

   
//close file
   
function close() {
       
fclose ($this->file);
    }

   
//get next line of text
   
function readLine() {
        while (
strpos($this->buffer, $this->delimiter)===false) {
           
$temp = fread ($this->file, $this->step);
           
$this->bytesRead += $this->step;

            if (
$temp) {
               
$this->buffer .= $temp;
            } else {
               
$temp = $this->buffer;
               
$this->buffer="";
                return
$temp;
            }
        }
       
$returnBuffer = substr($this->buffer, 0, strpos($this->buffer, $this->delimiter));
       
$this->buffer = substr($this->buffer, strpos($this->buffer, $this->delimiter) + strlen($this->delimiter));
        return
$returnBuffer;
    }

   
//check if there are more lines in the buffer
   
function hasMore() {
        return (((
$this->filesize - $this->bytesRead) > 0) || (strlen($this->buffer) > 0));
    }
}
?>



An example use of this class
<?php
$reader
= new Reader("hugefile.log");
$reader->open();
while (
$reader->hasMore()) {
   
$entry = $reader->readLine();
    echo
"$entry<br>";
}
$reader->close();
?>



filesplit : Split big text files in multiple small ones
Categories : PHP, Log Files, Filesystem, PHP Classes
Search and Replace Text : Searches Files for Specified Text and Replaces It by a Given Text
Categories : PHP, PHP Classes, Search, Filesystem
Class: Info on Users, Servers and the running script
Categories : PHP, Classes and Objects, User Interface, PHP Classes
Mssql database Manager
Categories : PHP, Databases, MS SQL Server, Classes and Objects, PHP Classes
PHP Transfer data from text file to Mysql Table
Categories : PHP, PHP Classes, Filesystem, Databases, MySQL
Easy upload class
Categories : PHP Classes, Filesystem, HTTP, PHP
ECHO-PHP Class Real Time Transaction Processor v1.4.4 for Credit Cards and Checks / ACH
Categories : PHP Classes, Cybercash, Classes and Objects, Ecommerce, PHP
PHP CLASS for ORACLE (database connectivity)
Categories : PHP, PHP Classes, Classes and Objects, Databases, Oracle
Scan Apache access log files and report possible worms attack
Categories : PHP, PHP Classes, Security, Apache, Log Files
MySQL Handler
Categories : PHP, Databases, MySQL, Classes and Objects, PHP Classes
Access_user Class - an easy to use system for protecting pages and register users.
Categories : PHP, Classes and Objects, Object Oriented, PHP Classes, Authentication
Compare two texts and display a block of text with the differences between them.
Categories : PHP, PHP Classes, Filesystem, Strings, Arrays
PHP4 DirectoryIterator Class
Categories : PHP, PHP Classes, Filesystem, Directories
A File Browser Class.To Read Drives,Directories and Files .Files writing is also possible
Categories : PHP, PHP Classes, Filesystem
file class , uploade file , download file already uploaded on another website
Categories : PHP, PHP Classes, Filesystem, Web Services