Login   Register  
PHP Classes
elePHPant
Icontem

File: cmd_class.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Hemp Cluster  >  cmd class  >  cmd_class.php  
File: cmd_class.php
Role: Class source
Content type: text/plain
Description: Class File
Class: cmd class
Access input/output data from command line scripts
 

Contents

Class file image Download
<?php
/***************************************************************************
 *                               cmd_class.php
 *                            -------------------
 *   begin                : Sunday, Okt 05, 2003
 *   copyright            : (C) 2003 Hemp "Jointy" Cluster
 *   email                : bestmischmaker@web.de
 *
 *   $Id: cmd_class.php, v.0.1.0 hempcluster Exp $
 *
 *    LastChange: <!--DATE-->Donnerstag, 20.11.2003 -- 12:21:28<!--/DATE-->
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/
class CMD
{
    var 
$buf_size;
    function 
cmd()
    {
        (
substr(PHP_OS,0,3) == 'WIN') ? $this->buf_size 4092 $this->buf_size 4094;
    }

    
/* same as $this->readline() */
    
function readln($bs='')
    {
        return 
$this->readline(&$bs);
    }

    
/****************************************************
     * @param - $buf_size max byte that will read
     * @return - input without lineend character ("\r\n","\n")
     ****************************************************/
    
function readline($buf_size '')
    {
        if(
$buf_size != '' && preg_match("/^[0-9]+$/",$buf_size)) $this->buf_size $buf_size;
        
$buf '';
        
$fp fopen("php://stdin" "r");
        
$buf fgets$fp, &$this->buf_size );
        
fclose($fp);
        return 
trim($buf);
    }

    
/****************************************************
     * @param $last_char - the last character that close input
     * @param $buf_size - like $this->readline()
     * @return - an numeric Array
     ****************************************************/
    
function readlines$last_char $buf_size '' )
    {
        
$buf = array();
        do
        {
            
$buf[] = $this->readline( &$buf_size );
        }
        while(
$buf[count($buf)-1] != $last_char );

        return 
$buf;
    }

    
/* same as $this->writeline() */
    
function writeln$str '' )
    {
        return 
$this->writeline(&$str);
    }

    
/****************************************************
     * @param $str - give here the line for output, but don't forget the lineend character
     * @return void
     ****************************************************/
    
function writeline$str '' )
    {
        
$fp fopen("php://stdout" "w");
        
fputs$fp $str strlen($str));
        
fclose($fp);
    }

    
/****************************************************
     * @param $str - give here the array with value as line content
     * @return void
     ****************************************************/
    
function writelines$arr )
    {
        while(list(,
$v) = each($arr))
        {
            
$this->writeline( &$v );
        }
    }

}

?>