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
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
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



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 : filesplit : Split big text files in multiple small ones
Categories : PHP, Log Files, Filesystem, PHP Classes Click here to Update Your Picture
Ben Yacoub Hatem
Date : May 29th 2004
Grade : 3 of 5 (graded 4 times)
Viewed : 20363
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Ben Yacoub Hatem
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?php

/**
* filesplit class : Split big text files in multiple files
*
* @package
* @author Ben Yacoub Hatem <[email protected]>
* @copyright Copyright (c) 2004
* @version $Id$ - 29/05/2004 09:02:10 - filesplit.class.php
* @access public
**/
class filesplit{
   
/**
     * Constructor
     * @access protected
     */
   
function filesplit(){
       
    }
   
   
/**
     * File to split
     * @access private
     * @var string
     **/
   
var $_source = 'logs.txt';
   
   
/**
     *
     * @access public
     * @return string
     **/
   
function Getsource(){
        return
$this->_source;
    }
   
   
/**
     *
     * @access public
     * @return void
     **/
   
function Setsource($newValue){
       
$this->_source = $newValue;
    }
   
   
/**
     * how much lines per file
     * @access private
     * @var integer
     **/
   
var $_lines = 1000;
   
   
/**
     *
     * @access public
     * @return integer
     **/
   
function Getlines(){
        return
$this->_lines;
    }
   
   
/**
     *
     * @access public
     * @return void
     **/
   
function Setlines($newValue){
       
$this->_lines = $newValue;
    }
   
   
/**
     * Folder to create splitted files with trail slash at end
     * @access private
     * @var string
     **/
   
var $_path = 'logs/';
   
   
/**
     *
     * @access public
     * @return string
     **/
   
function Getpath(){
        return
$this->_path;
    }
   
   
/**
     *
     * @access public
     * @return void
     **/
   
function Setpath($newValue){
       
$this->_path = $newValue;
    }

   
/**
     * Configure the class
     * @access public
     * @return void
     **/
   
function configure($source = "",$path = "",$lines = ""){
        if (
$source != "") {
           
$this->Setsource($source);
        }
        if (
$path!="") {
           
$this->Setpath($path);
        }
        if (
$lines!="") {
           
$this->Setlines($lines);
        }
    }
   
   
   
/**
     *
     * @access public
     * @return void
     **/
   
function run(){
       
$i=0;
       
$j=1;
       
$date = date("m-d-y");
        unset(
$buffer);
       
       
$handle = @fopen ($this->Getsource(), "r");
        while (!
feof ($handle)) {
         
$buffer .= @fgets($handle, 4096);
         
$i++;
              if (
$i >= $split) {
             
$fname = $this->Getpath()."part.$date.$j.txt";
               if (!
$fhandle = @fopen($fname, 'w')) {
                    print
"Cannot open file ($fname)";
                    exit;
               }
           
               if (!@
fwrite($fhandle, $buffer)) {
                   print
"Cannot write to file ($fname)";
                   exit;
               }
               
fclose($fhandle);
               
$j++;
               unset(
$buffer,$i);
                }
        }
       
fclose ($handle);
    }
   

}
?>


Usage Example
<?php
/**
* Sample usage of the filesplit class
*
* @package filesplit
* @author Ben Yacoub Hatem <[email protected]>
* @copyright Copyright (c) 2004
* @version $Id$ - 29/05/2004 09:14:06 - usage.php
* @access public
**/

require_once("filesplit.class.php");

$s = new filesplit;

/*
$s->Setsource("logs.txt");
$s->Setpath("logs/");
$s->Setlines(100); //number of lines that each new file will have after the split.
*/

$s->configure("logs.txt", "logs/", 2000);
$s->run();
?>



An efficient iterative and buffered text file reader
Categories : PHP, Classes and Objects, Filesystem, PHP Classes, Log Files
Scan Apache access log files and report possible worms attack
Categories : PHP, PHP Classes, Security, Apache, Log Files
PHP4 DirectoryIterator Class
Categories : PHP, PHP Classes, Filesystem, Directories
Compare two texts and display a block of text with the differences between them.
Categories : PHP, PHP Classes, Filesystem, Strings, Arrays
3 lines of Code to extract Tar, Zip, Gzip etc..
Categories : PHP, Filesystem, PHP Classes, Compression
Bs_IniHandler is a class that can read and write ini-style files (and strings)
Categories : PHP, Filesystem, PHP Classes
A File Browser Class.To Read Drives,Directories and Files .Files writing is also possible
Categories : PHP, PHP Classes, Filesystem
Remote Archive (Zip, Tar, Gzip) downloader with FTP and local extration support
Categories : PHP, FTP, Filesystem, PHP Classes, Compression
file class , uploade file , download file already uploaded on another website
Categories : PHP, PHP Classes, Filesystem, Web Services
PHP Based Apache + Mysql Error Log Parser
Categories : PHP, PHP Classes, Apache, MySQL, Log Files
logger class (PHP5 +)
Categories : PHP, PHP Classes, Log Files, XML
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
Search and Replace Text : Searches Files for Specified Text and Replaces It by a Given Text
Categories : PHP, PHP Classes, Search, Filesystem
Easy upload class
Categories : PHP Classes, Filesystem, HTTP, PHP
PHP Transfer data from text file to Mysql Table
Categories : PHP, PHP Classes, Filesystem, Databases, MySQL