WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
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 Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
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
Submit Site
Forex Trading Online forex trading platform

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 : 2 of 5 (graded 1 times)
Viewed : 5529
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 
 

<?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
file class , uploade file , download file already uploaded on another website
Categories : PHP, PHP Classes, Filesystem, Web Services
MySQL Handler
Categories : PHP, Databases, MySQL, Classes and Objects, PHP Classes
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
Class that allows the PHP developer to create and manage UNIX like password files suitable for use as Apache authentication password files.
Categories : HTTP, PHP, PHP Classes, Filesystem
Online Automatic Class Generator for MySQL Tables
Categories : PHP, PHP Classes, Classes and Objects, Databases, MySQL
PHP Based Apache + Mysql Error Log Parser
Categories : PHP, PHP Classes, Apache, MySQL, Log Files
A File Browser Class.To Read Drives,Directories and Files .Files writing is also possible
Categories : PHP, PHP Classes, Filesystem
3 lines of Code to extract Tar, Zip, Gzip etc..
Categories : PHP, Filesystem, PHP Classes, Compression
Class: Info on Users, Servers and the running script
Categories : PHP, Classes and Objects, User Interface, PHP Classes
Easy upload class
Categories : PHP Classes, Filesystem, HTTP, PHP
Remote Archive (Zip, Tar, Gzip) downloader with FTP and local extration support
Categories : PHP, FTP, Filesystem, PHP Classes, Compression
Search and Replace Text : Searches Files for Specified Text and Replaces It by a Given Text
Categories : PHP, PHP Classes, Search, Filesystem
Access_user Class - an easy to use system for protecting pages and register users.
Categories : PHP, Classes and Objects, Object Oriented, PHP Classes, Authentication
Bs_IniHandler is a class that can read and write ini-style files (and strings)
Categories : PHP, Filesystem, PHP Classes