72 lines
No EOL
1.5 KiB
PHP
72 lines
No EOL
1.5 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 affiche_titraille($html) {
|
|
$niv_h = [1,2,3,4,5,6];
|
|
$titraille = [];
|
|
foreach($niv_h as $h) {
|
|
preg_match_all('/<h'.$h.'>(.*)?<\/h'.$h.'>/si', $html, $match, PREG_SET_ORDER);
|
|
if ($match) {
|
|
foreach($match as $m) {
|
|
$titraille[] = '<h'.$h.'>'.$m[1].'</h'.$h.'>';
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return join("\r\n", $titraille);
|
|
}
|
|
|
|
function human_filesize($bytes, $decimals = 2) {
|
|
$sz = 'BKMGTP';
|
|
$factor = floor((strlen($bytes) - 1) / 3);
|
|
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor];
|
|
} |