- <?php
- /* ------------------------- */
- // Classe "File" ...
- class File
- {
- var $Path;
- var $Data;
- var $Handle;
- var $Cursor;
- // Constructeur ...
- function File($path)
- {
- $this -> Path = $path;
- $this -> Cursor = 0;
- }
- // Ouvre le fichier ...
- function Open()
- {
- $this -> Handle = fopen($this -> Path, 'r');
- }
- // Lit le caractère par rapport à la position du curseur.
- function Read($length = 1)
- {
- if(!$this -> WasOffsetRead($this -> GetCursorPosition()))
- {
- $byte_chains = fread($this -> Handle, $length);
- $this -> Data .= $byte_chains;
- }
- else
- {
- $byte_chains = substr($this -> Data, $this -> GetCursorPosition(), $length);
- }
- $this -> Cursor += $length;
- return $byte_chains;
- }
- // Positionne le curseur ...
- function Seek($offset, $whence = 'POSITION')
- {
- switch($whence)
- {
- case 'POSITION' :
- if(!$this -> WasOffsetRead($offset))
- {
- $this -> Read($offset - strlen($this -> Data));
- }
- $this -> Cursor = $offset;
- break;
- case 'MOVE' :
- if($offset > 0)
- {
- $this -> Read($offset);
- }
- $this -> Cursor += $offset;
- break;
- }
- }
- // Renvoie true ou false si le curseur est déjà passé par offset.
- function WasOffsetRead($offset)
- {
- return (strlen($this -> Data) <= $offset) ? false : true;
- }
- // Renvoie la position du cuseur ...
- function GetCursorPosition()
- {
- return $this -> Cursor;
- }
- // Renvoie true ou false si c'est la fin du fichier ...
- function IsEndOfFile()
- {
- return (feof($this -> Handle)) ? true : false;
- }
-
- // Ferme le flux vers le fichier ...
- function Close()
- {
- fclose($this -> Handle);
- }
- }
- /* ------------------------- */
- $fichier = new File('exemple.xml');
- $fichier -> Open();
- echo '<pre>';
- while(!$fichier -> IsEndOfFile())
- {
- echo htmlentities($fichier -> Read());
- }
- echo '</pre>';
- $fichier -> Close();
- /* ------------------------- */
- ?>
<?php
/* ------------------------- */
// Classe "File" ...
class File
{
var $Path;
var $Data;
var $Handle;
var $Cursor;
// Constructeur ...
function File($path)
{
$this -> Path = $path;
$this -> Cursor = 0;
}
// Ouvre le fichier ...
function Open()
{
$this -> Handle = fopen($this -> Path, 'r');
}
// Lit le caractère par rapport à la position du curseur.
function Read($length = 1)
{
if(!$this -> WasOffsetRead($this -> GetCursorPosition()))
{
$byte_chains = fread($this -> Handle, $length);
$this -> Data .= $byte_chains;
}
else
{
$byte_chains = substr($this -> Data, $this -> GetCursorPosition(), $length);
}
$this -> Cursor += $length;
return $byte_chains;
}
// Positionne le curseur ...
function Seek($offset, $whence = 'POSITION')
{
switch($whence)
{
case 'POSITION' :
if(!$this -> WasOffsetRead($offset))
{
$this -> Read($offset - strlen($this -> Data));
}
$this -> Cursor = $offset;
break;
case 'MOVE' :
if($offset > 0)
{
$this -> Read($offset);
}
$this -> Cursor += $offset;
break;
}
}
// Renvoie true ou false si le curseur est déjà passé par offset.
function WasOffsetRead($offset)
{
return (strlen($this -> Data) <= $offset) ? false : true;
}
// Renvoie la position du cuseur ...
function GetCursorPosition()
{
return $this -> Cursor;
}
// Renvoie true ou false si c'est la fin du fichier ...
function IsEndOfFile()
{
return (feof($this -> Handle)) ? true : false;
}
// Ferme le flux vers le fichier ...
function Close()
{
fclose($this -> Handle);
}
}
/* ------------------------- */
$fichier = new File('exemple.xml');
$fichier -> Open();
echo '<pre>';
while(!$fichier -> IsEndOfFile())
{
echo htmlentities($fichier -> Read());
}
echo '</pre>';
$fichier -> Close();
/* ------------------------- */
?>