array_php в подарок, в честь выхода PHP5

ForJest

- свежая кровь
array_php в подарок, в честь выхода PHP5

Дарю всем желающим очень нужную в хозяйстве функцию
PHP:
  function array_php($array, $ident = 0)
  //returns php represenation of $array
  {
       if (!is_array($array)) return false;
       ob_start();
       print_r($array);

       $res=preg_replace(
              array('/"/',
                    "/\=>([ ]+)(?!array)([^\n]*)\n(?![ ]*\))/i", 
                    "/=>([ ]+)(?!array)([^\n]*)\n(?=[ ]*\))/i",
                    "/\[(.*)\](?= \=>)/", 
                    "~([\"'])(\d+)\\1~",
                    "/\)\n\n(?![ ]*\))/smi", 
                    "/Array/i"
                    ), 
              array('\\"',
                    "=> \\1\"\\2\",\n", 
                    "=> \\1\"\\2\"\n", 
                    "'\\1'",
                    "\\2", 
                    "),\n\n",
                    "array"),
                    (substr(ob_get_contents(),0, -1).";"));

       ob_end_clean();
       if ((int)$ident)
       {
             $strings = explode("\n", $res);
             $ident_str = str_repeat(" ", $ident);
             reset ($strings);
             while (list($key, $val) = each($strings))
             {
                  $strings[$key] = strlen(trim($val))?$ident_str.$val:trim($val);
             }
             $res = implode("\n", $strings);
       }
       return $res;
  }
 

Profic

just Profic (PHP5 BetaTeam)
тогда уж и я подарок сделаю :)
массив-класс работающий аналогично встроенному типу array, но в виде отдельно класса :) Отличия от ArrayObject:
1) поддержка оператора [] (кстати сам я этим классом не пользовался, но увидев метод append решил, что оно не работает, но сам не проверял) в полном соответствии с array
2) возможность (опциональная) ограничить индексов
PHP:
<?php
class rtfHelperArray implements arrayAccess, iteratorAggregate {
	private $haStore = array ();
	private $haProps = NULL;
	private $haCheck = false;

	protected function __construct () {}
	public function __destruct () {}

	final protected function haPropsSet () {
		$args = func_get_args ();
		if (!sizeof ($args)) {
			throw new Exception ('At least one prop must be specified');
			return false;
		}
		$this->haProps = array ();
		foreach ($args as $arg) {
			$this->haProps[$arg] = true;
		}
		return true;
	}

	final protected function haPropsSetRef (&$props) {
		$this->haProps = &$props;
		return true;
	}

	final protected function haPropsTransfer (self $arrayObj) {
		$arrayObj->haPropsSetRef ($this->haProps);
		return true;
	}

	final protected function haPropsClear () {
		unset ($this->haProps);
		return true;
	}

	final protected function haCheckSet ($check) {
		$this->haCheck = $check;
		return true;
	}

	final public function getIterator () {
		return new arrayIterator ($this->haStore);
	}

	final public function offsetExists ($offset) {
		return array_key_exists ($offset, $this->haStore);
	}

	final public function offsetGet ($offset) {
		if (array_key_exists ($offset, $this->haStore)) {
			return $this->haStore[$offset];
		} else {
			return NULL;
		}
	}

	final public function offsetSet ($offset, $value) {
		if (!$this->haCheck && $offset === NULL) {
			if (sizeof ($this->haStore)) {
				$last = (int) max (array_keys ($this->haStore));
				$offset = $last > 0 || array_key_exists ($last, $this->haStore) ? ++$last : 0;
			} else {
				$offset = 0;
			}
		}
		if (!is_string ($offset) && !is_int ($offset)) {
			throw new Exception (
				'\'' . $offset . '\' (' . getType ($offset) . ') = '
				. '"' . $value . '" (' . getType ($value) . '): '
				. 'offset is not string or int'
			);
			return false;
		}
		if ($this->haCheck && !isset ($this->haProps[$offset])) {
			throw new Exception (
				'\'' . $offset . '\' (' . getType ($offset) . ') = '
				. '"' . $value . '" (' . getType ($value) . '): '
				. 'offset is unknown'
			);
			return false;
		}
		$this->haStore[$offset] = $value;
		return true;
	}

	final public function offsetUnset ($offset) {
		unset ($this->haStore[$offset]);
		return true;
	}
}
?>
Пример использования
PHP:
<?php
include 'class.rtfHelperArray.php';
$o = new rtfHelperArray ();
$o[-2] = -2;
$o[] = 0;
unset ($o[0]);
$o['a'] = 'a';
$o[] = 0;
$o[] = 1;
?>
 

young

Новичок
И от меня тогда подарок приймите
Я думаю он многим пригодится!
И давайте вообще, каждый сделает по подарку!

PHP:
class OLE_PPS_Root extends OLE_PPS
{
    /**
    * The temporary dir for storing the OLE file
    * @var string
    */
    var $_tmp_dir;
    
    /**
    * Constructor
    *
    * @access public
    * @param integer $time_1st A timestamp
    * @param integer $time_2nd A timestamp
    */
    function OLE_PPS_Root($time_1st, $time_2nd, $raChild)
    {
        $this->_tmp_dir = '';
        $this->OLE_PPS(
           null, 
           OLE::Asc2Ucs('Root Entry'),
           OLE_PPS_TYPE_ROOT,
           null,
           null,
           null,
           $time_1st,
           $time_2nd,
           null,
           $raChild);
    }

    /**
    * Sets the temp dir used for storing the OLE file
    *
    * @access public
    * @param string $dir The dir to be used as temp dir
    * @return true if given dir is valid, false otherwise
    */
    function setTempDir($dir)
    {
        if (is_dir($dir)) {
            $this->_tmp_dir = $dir;
            return true;
        }
        return false;
    }

    /**
    * Method for saving the whole OLE container (including files).
    * In fact, if called with an empty argument (or '-'), it saves to a
    * temporary file and then outputs it's contents to stdout.
    *
    * @param string $filename The name of the file where to save the OLE container
    * @access public
    * @return mixed true on success, PEAR_Error on failure
    */
    function save($filename)
    {
        // Initial Setting for saving
        $this->_BIG_BLOCK_SIZE  = pow(2,
                      ((isset($this->_BIG_BLOCK_SIZE))? $this->_adjust2($this->_BIG_BLOCK_SIZE)  : 9));
        $this->_SMALL_BLOCK_SIZE= pow(2, 
                      ((isset($this->_SMALL_BLOCK_SIZE))?  $this->_adjust2($this->_SMALL_BLOCK_SIZE): 6));
 
        // Open temp file if we are sending output to stdout
        if (($filename == '-') or ($filename == ''))
        {
            $this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_Root");
            $this->_FILEH_ = @fopen($this->_tmp_filename,"w+b");
            if ($this->_FILEH_ == false) {
                return $this->raiseError("Can't create temporary file.");
            }
        }
        else
        {
            $this->_FILEH_ = @fopen($filename, "wb");
            if ($this->_FILEH_ == false) {
                return $this->raiseError("Can't open $filename. It may be in use or protected.");
            }
        }
        // Make an array of PPS's (for Save)
        $aList = array();
        $this->_savePpsSetPnt($aList);
        // calculate values for header
        list($iSBDcnt, $iBBcnt, $iPPScnt) = $this->_calcSize($aList); //, $rhInfo);
        // Save Header
        $this->_saveHeader($iSBDcnt, $iBBcnt, $iPPScnt);
  
        // Make Small Data string (write SBD)
        $this->_data = $this->_makeSmallData($aList);
  
        // Write BB
        $this->_saveBigData($iSBDcnt, $aList);
        // Write PPS
        $this->_savePps($aList);
        // Write Big Block Depot and BDList and Adding Header informations
        $this->_saveBbd($iSBDcnt, $iBBcnt, $iPPScnt);
        // Close File, send it to stdout if necessary
        if(($filename == '-') or ($filename == ''))
        {
            fseek($this->_FILEH_, 0);
            fpassthru($this->_FILEH_);
            @fclose($this->_FILEH_);
            // Delete the temporary file.
            @unlink($this->_tmp_filename);
        }
        else {
            @fclose($this->_FILEH_);
        }
        return true;
    }

    /**
    * Calculate some numbers
    *
    * @access private
    * @param array $raList Reference to an array of PPS's
    * @return array The array of numbers
    */
    function _calcSize(&$raList) 
    {
        // Calculate Basic Setting
        list($iSBDcnt, $iBBcnt, $iPPScnt) = array(0,0,0);
        $iSmallLen = 0;
        $iSBcnt = 0;
        for ($i = 0; $i < count($raList); $i++) {
            if($raList[$i]->Type == OLE_PPS_TYPE_FILE) {
                $raList[$i]->Size = $raList[$i]->_DataLen();
                if($raList[$i]->Size < OLE_DATA_SIZE_SMALL) {
                    $iSBcnt += floor($raList[$i]->Size / $this->_SMALL_BLOCK_SIZE)
                                  + (($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)? 1: 0);
                }
                else {
                    $iBBcnt += (floor($raList[$i]->Size / $this->_BIG_BLOCK_SIZE) +
                        (($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)? 1: 0));
                }
            }
        }
        $iSmallLen = $iSBcnt * $this->_SMALL_BLOCK_SIZE;
        $iSlCnt = floor($this->_BIG_BLOCK_SIZE / OLE_LONG_INT_SIZE);
        $iSBDcnt = floor($iSBcnt / $iSlCnt) + (($iSBcnt % $iSlCnt)? 1:0);
        $iBBcnt +=  (floor($iSmallLen / $this->_BIG_BLOCK_SIZE) +
                      (( $iSmallLen % $this->_BIG_BLOCK_SIZE)? 1: 0));
        $iCnt = count($raList);
        $iBdCnt = $this->_BIG_BLOCK_SIZE / OLE_PPS_SIZE;
        $iPPScnt = (floor($iCnt/$iBdCnt) + (($iCnt % $iBdCnt)? 1: 0));
   
        return array($iSBDcnt, $iBBcnt, $iPPScnt);
    }

    /**
    * Helper function for caculating a magic value for block sizes
    *
    * @access private
    * @param integer $i2 The argument
    * @see save()
    * @return integer
    */
    function _adjust2($i2)
    {
        $iWk = log($i2)/log(2);
        return ($iWk > floor($iWk))? floor($iWk)+1:$iWk;
    }

    /**
    * Save OLE header
    *
    * @access private
    * @param integer $iSBDcnt
    * @param integer $iBBcnt
    * @param integer $iPPScnt
    */
    function _saveHeader($iSBDcnt, $iBBcnt, $iPPScnt)
    {
        $FILE = $this->_FILEH_;
  
        // Calculate Basic Setting
        $iBlCnt = $this->_BIG_BLOCK_SIZE / OLE_LONG_INT_SIZE;
        $i1stBdL = ($this->_BIG_BLOCK_SIZE - 0x4C) / OLE_LONG_INT_SIZE;
  
        $iBdExL = 0;
        $iAll = $iBBcnt + $iPPScnt + $iSBDcnt;
        $iAllW = $iAll;
        $iBdCntW = floor($iAllW / $iBlCnt) + (($iAllW % $iBlCnt)? 1: 0);
        $iBdCnt = floor(($iAll + $iBdCntW) / $iBlCnt) + ((($iAllW+$iBdCntW) % $iBlCnt)? 1: 0);
  
        // Calculate BD count
        if ($iBdCnt >$i1stBdL)
        {
            while (1)
            {
                $iBdExL++;
                $iAllW++;
                $iBdCntW = floor($iAllW / $iBlCnt) + (($iAllW % $iBlCnt)? 1: 0);
                $iBdCnt = floor(($iAllW + $iBdCntW) / $iBlCnt) + ((($iAllW+$iBdCntW) % $iBlCnt)? 1: 0);
                if ($iBdCnt <= ($iBdExL*$iBlCnt+ $i1stBdL)) {
                    break;
                }
            }
        }
  
        // Save Header
        fwrite($FILE,
                  "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1"
                  . "\x00\x00\x00\x00"
                  . "\x00\x00\x00\x00"
                  . "\x00\x00\x00\x00"
                  . "\x00\x00\x00\x00"
                  . pack("v", 0x3b)
                  . pack("v", 0x03)
                  . pack("v", -2)
                  . pack("v", 9)
                  . pack("v", 6)
                  . pack("v", 0)
                  . "\x00\x00\x00\x00"
                  . "\x00\x00\x00\x00"
                  . pack("V", $iBdCnt) 
                  . pack("V", $iBBcnt+$iSBDcnt) //ROOT START
                  . pack("V", 0)
                  . pack("V", 0x1000)
                  . pack("V", 0)                  //Small Block Depot
                  . pack("V", 1)
          );
        // Extra BDList Start, Count
        if ($iBdCnt < $i1stBdL)
        {
            fwrite($FILE,
                      pack("V", -2).      // Extra BDList Start
                      pack("V", 0)        // Extra BDList Count
                  );
        }
        else
        {
            fwrite($FILE, pack("V", $iAll+$iBdCnt) . pack("V", $iBdExL));
        }

        // BDList
        for ($i=0; $i<$i1stBdL and $i < $iBdCnt; $i++) {
            fwrite($FILE, pack("V", $iAll+$i));
        }
        if ($i < $i1stBdL)
        {
            for ($j = 0; $j < ($i1stBdL-$i); $j++) {
                fwrite($FILE, (pack("V", -1)));
            }
        }
    }

    /**
    * Saving big data (PPS's with data bigger than OLE_DATA_SIZE_SMALL)
    *
    * @access private
    * @param integer $iStBlk
    * @param array &$raList Reference to array of PPS's
    */
    function _saveBigData($iStBlk, &$raList)
    {
        $FILE = $this->_FILEH_;
   
        // cycle through PPS's
        for ($i = 0; $i < count($raList); $i++)
        {
            if($raList[$i]->Type != OLE_PPS_TYPE_DIR)
            {
                $raList[$i]->Size = $raList[$i]->_DataLen();
                if(($raList[$i]->Size >= OLE_DATA_SIZE_SMALL) or
                    (($raList[$i]->Type == OLE_PPS_TYPE_ROOT) and isset($raList[$i]->_data)))
                {
                    // Write Data
                    if(isset($raList[$i]->_PPS_FILE))
                    {
                        $iLen = 0;
                        fseek($raList[$i]->_PPS_FILE, 0); // To The Top
                        while($sBuff = fread($raList[$i]->_PPS_FILE, 4096))
                        {
                            $iLen += strlen($sBuff);
                            fwrite($FILE, $sBuff);
                        }
                    }
                    else {
                        fwrite($FILE, $raList[$i]->_data);
                    }
           
                    if ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)
                    {
                        for ($j = 0; $j < ($this->_BIG_BLOCK_SIZE - ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)); $j++) {
                            fwrite($FILE, "\x00");
                        }
                    }
                    // Set For PPS
                    $raList[$i]->_StartBlock = $iStBlk;
                    $iStBlk += 
                            (floor($raList[$i]->Size / $this->_BIG_BLOCK_SIZE) +
                                (($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)? 1: 0));
                }
                // Close file for each PPS, and unlink it
                if (isset($raList[$i]->_PPS_FILE))
                {
                    @fclose($raList[$i]->_PPS_FILE);
                    $raList[$i]->_PPS_FILE = null;
                    @unlink($raList[$i]->_tmp_filename);
                }
            }
        }
    }

    /**
    * get small data (PPS's with data smaller than OLE_DATA_SIZE_SMALL)
    *
    * @access private
    * @param array &$raList Reference to array of PPS's
    */
    function _makeSmallData(&$raList)
    {
        $sRes = '';
        $FILE = $this->_FILEH_;
        $iSmBlk = 0;
   
        for ($i = 0; $i < count($raList); $i++)
        {
            // Make SBD, small data string
            if ($raList[$i]->Type == OLE_PPS_TYPE_FILE)
            {
                if ($raList[$i]->Size <= 0) {
                    continue;
                }
                if ($raList[$i]->Size < OLE_DATA_SIZE_SMALL)
                {
                    $iSmbCnt = floor($raList[$i]->Size / $this->_SMALL_BLOCK_SIZE)
                                  + (($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)? 1: 0);
                    // Add to SBD
                    for ($j = 0; $j < ($iSmbCnt-1); $j++) {
                        fwrite($FILE, pack("V", $j+$iSmBlk+1));
                    }
                    fwrite($FILE, pack("V", -2));
                   
                    // Add to Data String(this will be written for RootEntry)
                    if ($raList[$i]->_PPS_FILE)
                    {
                        fseek($raList[$i]->_PPS_FILE, 0); // To The Top
                        while ($sBuff = fread($raList[$i]->_PPS_FILE, 4096)) {
                            $sRes .= $sBuff;
                        }
                    }
                    else {
                        $sRes .= $raList[$i]->_data;
                    }
                    if($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)
                    {
                        for ($j = 0; $j < ($this->_SMALL_BLOCK_SIZE - ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)); $j++) {
                            $sRes .= "\x00";
                        }
                    }
                    // Set for PPS
                    $raList[$i]->_StartBlock = $iSmBlk;
                    $iSmBlk += $iSmbCnt;
                }
            }
        }
        $iSbCnt = floor($this->_BIG_BLOCK_SIZE / OLE_LONG_INT_SIZE);
        if($iSmBlk % $iSbCnt)
        {
            for ($i = 0; $i < ($iSbCnt - ($iSmBlk % $iSbCnt)); $i++) {
                fwrite($FILE, pack("V", -1));
            }
        }
        return $sRes;
    }

    /**
    * Saves all the PPS's WKs
    *
    * @access private
    * @param array $raList Reference to an array with all PPS's
    */
    function _savePps(&$raList) 
    {
        // Save each PPS WK
        for ($i = 0; $i < count($raList); $i++) {
            fwrite($this->_FILEH_, $raList[$i]->_getPpsWk());
        }
        // Adjust for Block
        $iCnt = count($raList);
        $iBCnt = $this->_BIG_BLOCK_SIZE / OLE_PPS_SIZE;
        if ($iCnt % $iBCnt)
        {
            for ($i = 0; $i < (($iBCnt - ($iCnt % $iBCnt)) * OLE_PPS_SIZE); $i++) {
                fwrite($this->_FILEH_, "\x00");
            }
        }
    }

    /**
    * Saving Big Block Depot
    *
    * @access private
    * @param integer $iSbdSize
    * @param integer $iBsize
    * @param integer $iPpsCnt
    */
    function _saveBbd($iSbdSize, $iBsize, $iPpsCnt) 
    {
        $FILE = $this->_FILEH_;
        // Calculate Basic Setting
        $iBbCnt = $this->_BIG_BLOCK_SIZE / OLE_LONG_INT_SIZE;
        $i1stBdL = ($this->_BIG_BLOCK_SIZE - 0x4C) / OLE_LONG_INT_SIZE;
      
        $iBdExL = 0;
        $iAll = $iBsize + $iPpsCnt + $iSbdSize;
        $iAllW = $iAll;
        $iBdCntW = floor($iAllW / $iBbCnt) + (($iAllW % $iBbCnt)? 1: 0);
        $iBdCnt = floor(($iAll + $iBdCntW) / $iBbCnt) + ((($iAllW+$iBdCntW) % $iBbCnt)? 1: 0);
        // Calculate BD count
        if ($iBdCnt >$i1stBdL)
        {
            while (1)
            {
                $iBdExL++;
                $iAllW++;
                $iBdCntW = floor($iAllW / $iBbCnt) + (($iAllW % $iBbCnt)? 1: 0);
                $iBdCnt = floor(($iAllW + $iBdCntW) / $iBbCnt) + ((($iAllW+$iBdCntW) % $iBbCnt)? 1: 0);
                if ($iBdCnt <= ($iBdExL*$iBbCnt+ $i1stBdL)) {
                    break;
                }
            }
        }
      
        // Making BD
        // Set for SBD
        if ($iSbdSize > 0)
        {
            for ($i = 0; $i<($iSbdSize-1); $i++) {
                fwrite($FILE, pack("V", $i+1));
            }
            fwrite($FILE, pack("V", -2));
        }
        // Set for B
        for ($i = 0; $i<($iBsize-1); $i++) {
            fwrite($FILE, pack("V", $i+$iSbdSize+1));
        }
        fwrite($FILE, pack("V", -2));
      
        // Set for PPS
        for ($i = 0; $i<($iPpsCnt-1); $i++) {
            fwrite($FILE, pack("V", $i+$iSbdSize+$iBsize+1));
        }
        fwrite($FILE, pack("V", -2));
        // Set for BBD itself ( 0xFFFFFFFD : BBD)
        for ($i=0; $i<$iBdCnt;$i++) {
            fwrite($FILE, pack("V", 0xFFFFFFFD));
        }
        // Set for ExtraBDList
        for ($i=0; $i<$iBdExL;$i++) {
            fwrite($FILE, pack("V", 0xFFFFFFFC));
        }
        // Adjust for Block
        if (($iAllW + $iBdCnt) % $iBbCnt)
        {
            for ($i = 0; $i < ($iBbCnt - (($iAllW + $iBdCnt) % $iBbCnt)); $i++) {
                fwrite($FILE, pack("V", -1));
            }
        }
        // Extra BDList
        if ($iBdCnt > $i1stBdL)
        {
            $iN=0;
            $iNb=0;
            for ($i=$i1stBdL;$i<$iBdCnt; $i++, $iN++)
            {
                if ($iN>=($iBbCnt-1))
                {
                    $iN = 0;
                    $iNb++;
                    fwrite($FILE, pack("V", $iAll+$iBdCnt+$iNb));
                }
                fwrite($FILE, pack("V", $iBsize+$iSbdSize+$iPpsCnt+$i));
            }
            if (($iBdCnt-$i1stBdL) % ($iBbCnt-1))
            {
                for ($i = 0; $i < (($iBbCnt-1) - (($iBdCnt-$i1stBdL) % ($iBbCnt-1))); $i++) {
                    fwrite($FILE, pack("V", -1)); 
                }
            }
            fwrite($FILE, pack("V", -2));
        }
    }
}
 

Profic

just Profic (PHP5 BetaTeam)
young
Эта... class OLE_PPS_Root extends OLE_PPS ни о чем не говорит? :)
К тому же что этот класс делает? PowerPoint-овские файлы пишет? :)
 

young

Новичок
Эта... class OLE_PPS_Root extends OLE_PPS ни о чем не говорит?
Да, совсем забыл. Держи еще и его
PHP:
class OLE_PPS extends PEAR
{
    /**
    * The PPS index
    * @var integer
    */
    var $No;

    /**
    * The PPS name (in Unicode)
    * @var string
    */
    var $Name;
 
    /**
    * The PPS type. Dir, Root or File
    * @var integer
    */
    var $Type;
 
    /**
    * The index of the previous PPS
    * @var integer
    */
    var $PrevPps;
 
    /**
    * The index of the next PPS
    * @var integer
    */
    var $NextPps;
 
    /**
    * The index of it's first child if this is a Dir or Root PPS
    * @var integer
    */
    var $DirPps;
 
    /**
    * A timestamp
    * @var integer
    */
    var $Time1st;

    /**
    * A timestamp
    * @var integer
    */
    var $Time2nd;

    /**
    * Starting block (small or big) for this PPS's data  inside the container
    * @var integer
    */
    var $_StartBlock;

    /**
    * The size of the PPS's data (in bytes)
    * @var integer
    */
    var $Size;

    /**
    * The PPS's data (only used if it's not using a temporary file)
    * @var string
    */
    var $_data;

    /**
    * Array of child PPS's (only used by Root and Dir PPS's)
    * @var array
    */
    var $children = array();

    /**
    * The constructor
    *
    * @access public
    * @param integer $No   The PPS index
    * @param string $name  The PPS name (in Unicode)
    * @param integer $type The PPS type. Dir, Root or File
    * @param integer $prev The index of the previous PPS
    * @param integer $next The index of the next PPS
    * @param integer $dir  The index of it's first child if this is a Dir or Root PPS
    * @param integer $time_1st A timestamp
    * @param integer $time_2nd A timestamp
    * @param array   $children Array containing children PPS for this PPS
    */
    function OLE_PPS($No, $name, $type, $prev, $next, $dir, $time_1st, $time_2nd, $data, $children)
    {
        $this->No      = $No;
        $this->Name    = $name;
        $this->Type    = $type;
        $this->PrevPps = $prev;
        $this->NextPps = $next;
        $this->DirPps  = $dir;
        $this->Time1st = $time_1st;
        $this->Time2nd = $time_2nd;
        $this->_data      = $data;
        $this->children   = $children;
        if ($data != '') {
            $this->Size = strlen($data);
        }
        else {
            $this->Size = 0;
        }
    }

    /**
    * Returns the amount of data saved for this PPS
    *
    * @access private
    * @return integer The amount of data (in bytes)
    */
    function _DataLen()
    {
        if (!isset($this->_data)) {
            return 0;
        }
        if (isset($this->_PPS_FILE))
        {
            fseek($this->_PPS_FILE, 0);
            $stats = fstat($this->_PPS_FILE);
            return $stats[7];
        }
        else {
            return strlen($this->_data);
        }
    }

    /**
    * Returns a string with the PPS's WK (What is a WK?)
    *
    * @access private
    * @return string The binary string
    */
    function _getPpsWk()
    {
        $ret = $this->Name;
        for ($i = 0; $i < (64 - strlen($this->Name)); $i++) {
            $ret .= "\x00";
        }
        $ret .= pack("v", strlen($this->Name) + 2)  // 66
              . pack("c", $this->Type)              // 67
              . pack("c", 0x00) //UK                // 68
              . pack("V", $this->PrevPps) //Prev    // 72
              . pack("V", $this->NextPps) //Next    // 76
              . pack("V", $this->DirPps)  //Dir     // 80
              . "\x00\x09\x02\x00"                  // 84
              . "\x00\x00\x00\x00"                  // 88
              . "\xc0\x00\x00\x00"                  // 92
              . "\x00\x00\x00\x46"                  // 96 // Seems to be ok only for Root
              . "\x00\x00\x00\x00"                  // 100
              . OLE::LocalDate2OLE($this->Time1st)       // 108
              . OLE::LocalDate2OLE($this->Time2nd)       // 116
              . pack("V", isset($this->_StartBlock)? 
                        $this->_StartBlock:0)        // 120
              . pack("V", $this->Size)               // 124
              . pack("V", 0);                        // 128
        return $ret;
    }

    /**
    * Updates index and pointers to previous, next and children PPS's for this
    * PPS. I don't think it'll work with Dir PPS's.
    *
    * @access private
    * @param array &$pps_array Reference to the array of PPS's for the whole OLE
    *                          container 
    * @return integer          The index for this PPS
    */
    function _savePpsSetPnt(&$pps_array) 
    {
        $pps_array[count($pps_array)] = &$this;
        $this->No = count($pps_array) - 1;
        $this->PrevPps = 0xFFFFFFFF;
        $this->NextPps = 0xFFFFFFFF;
        if (count($this->children) > 0) {
            $this->DirPps = $this->children[0]->_savePpsSetPnt($pps_array);
        }
        else {
            $this->DirPps = 0xFFFFFFFF;
        }
        return $this->No;
    }
}
 

Profic

just Profic (PHP5 BetaTeam)
young
Самое главное забыл :) Что он делает? Т.к. разбираться в километрах исходников, только для того, чтобы понять, что они делают ИМХО, как-то странно :)
 

Profic

just Profic (PHP5 BetaTeam)
:)
А можно я закину сюда свой исходник 4-годичной давности? Он красивый, но по своему :) Сайтик на файлах :) Параметры в виде http://www.example.com?archive+current+52 :)
 

ForJest

- свежая кровь
nightik
Об этой фун-ции не знал. Ибо код писался под 4.1. Спасибо.
Profic
А сайтик в хозяйстве пригодится? :)
Вот моя фунция - не пригодится уже. Получается, что подарок получил я :)
 

Kelkos

Сам себе программер
тляцкий кот! Давай кто больше кода напечатает?! Вот у меня, например, есть скрипт на 3000 строк.. подойдёт? (и главное я никому не расскажу что он в итоге делает)
 

HEm

Сетевой бобер
Kelkos
когда наберешь в форуме > 300 сообщений - плиз
 

Profic

just Profic (PHP5 BetaTeam)
ForJest
Сайтик - сейчас врядли :) Писался он еще под php3 :) Но что удивительно запустил его сейчас, а он работает под вторничным снапшотом php5 :) (Правда со скрипом и пришлось E_NOTICE отключить :))
А вот rtfHelperArray ИМХО вещь полезная для определенных целей :)
 

ForJest

- свежая кровь
Kelkos
Главное чтобы он в хозяйстве мог пригодится... А размер не важен :)
 
Сверху