50 lines
No EOL
978 B
PHP
50 lines
No EOL
978 B
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;
|
|
} |