56 lines
No EOL
1.1 KiB
PHP
56 lines
No EOL
1.1 KiB
PHP
<?php
|
|
/**
|
|
* Fonctions utiles au plugin Traitement corpus web
|
|
*
|
|
* @plugin Traitement corpus web
|
|
* @copyright 2021
|
|
* @author gamuza
|
|
* @licence GNU/GPL
|
|
* @package SPIP\Corpus\Fonctions
|
|
*/
|
|
|
|
if (!defined('_ECRIRE_INC_VERSION')) {
|
|
return;
|
|
}
|
|
|
|
|
|
function nombre_ligne($fichier) {
|
|
if (!file_exists($fichier)) {
|
|
return false;
|
|
}
|
|
$num_ligne = 0;
|
|
$handle = @fopen($fichier, "rb");
|
|
if ($handle) {
|
|
while (($buffer = fgets($handle)) !== false) {
|
|
$num_ligne = $num_ligne + 1;
|
|
}
|
|
}
|
|
return $num_ligne;
|
|
}
|
|
|
|
function affiche_ligne($fichier, $num) {
|
|
if (!file_exists($fichier)) {
|
|
return false;
|
|
}
|
|
|
|
$handle = @fopen($fichier, "rb");
|
|
if ($handle) {
|
|
while (($buffer = fgets($handle)) !== false) {
|
|
$num_ligne = $num_ligne + 1;
|
|
if ($num_ligne == $num) {
|
|
return $buffer;
|
|
}
|
|
}
|
|
if (!feof($handle)) {
|
|
echo "Erreur: fgets() a échoué\n";
|
|
}
|
|
fclose($handle);
|
|
}
|
|
return 'Erreur : nombre de lignes du fichier '.$fichier.' inférieur à '.$num;
|
|
}
|
|
|
|
function human_filesize($bytes, $decimals = 2) {
|
|
$sz = 'BKMGTP';
|
|
$factor = floor((strlen($bytes) - 1) / 3);
|
|
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor];
|
|
} |