<?php
@link http://pear.php.net/bugs/bug.php?id=4295
require_once 'File/CSV.php';
function dump(&$var, $title = null, $hex = false)
{
if (isset($title)) {
echo "<h2>$title</h2>";
}
echo '<pre>';
if ($hex) {
var_dump(bin2hex($var));
} else {
var_dump($var);
}
echo '</pre>';
}
$filename = 'LISTE_REG.txt';
function searchReg($regKey)
{
global $filename, $conf;
$data = array();
while ($r = File_CSV::read($filename, $conf)) {
if (trim($r[0]) != $regKey) {
continue;
}
$data[] = array('COD_REG' => trim($r[0]), 'LIB_REG' => trim($r[1]));
break;
}
File::close($filename, FILE_MODE_READ);
return $data;
}
$conf = array('fields' => 3, 'sep' => ';', 'crlf' => "\r\n");
dump($conf['crlf'], "crlf used to read file $filename : \"\\r\\n\" (hexa value follow)", true);
$data = file_get_contents($filename);
dump($data);
$conf = array('fields' => 3, 'sep' => ';', 'crlf' => "\n\r");
dump($conf['crlf'], "crlf used to read file $filename : \"\\n\\r\" (hexa value follow)", true);
$reg = 11;
$data = searchReg($reg);
echo "<h2>Search result of region $reg</h2>";
dump($data);
$filePointers = &PEAR::getStaticProperty('File', 'filePointers');
dump($filePointers, 'file pointers stack after File::close calls');
$conf = array('fields' => 3, 'sep' => ';', 'crlf' => "\15\12");
dump($conf['crlf'], "crlf used to read file $filename : \"\\15\\12\" (hexa value follow)", true);
$reg = 54;
$data = searchReg($reg);
echo "<h2>Search result of region $reg</h2>";
dump($data);
$filePointers = &PEAR::getStaticProperty('File', 'filePointers');
dump($filePointers, 'file pointers stack after File::close calls');
$conf = array('fields' => 3, 'sep' => ';', 'crlf' => '\r\n');
dump($conf['crlf'], "crlf used to read file $filename : '\\r\\n' (hexa value follow)", true);
$reg = 22;
$data = searchReg($reg);
echo "<h2>Search result of region $reg</h2>";
dump($data);
$filePointers = &PEAR::getStaticProperty('File', 'filePointers');
dump($filePointers, 'file pointers stack after File::close calls');
?> |