PHP Classes
Icontem

File: cmd_class.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet 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 );
        }
    }

}

?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products