W dniu 26.09.2019 o 12:49, RM pisze:
> W dniu 26.09.2019 o 12:13, Jivanmukta pisze:
>
>> A czy istnieją gotowe takie skrypty, bo nie udało mi się znaleźć w sieci?
>
> Czy ktoś napisałby odpłatnie dla mnie taki skrypt, który działałby offline?
Napisałem taki, może się komuś przyda:
<?php
if (!isset($argv[1]) || isset($argv[3])) {
die('Usage: php ' . $argv[0] . " file.html minpercent\nDefault
minpercent is 7, value must be in range 0...100.\n");
}
if (!file_exists($argv[1])) {
die(sprintf("File %s does not exist.\n", $argv[1]));
}
if (isset($argv[2])) {
$minpercent = (float)$argv[2];
if ($minpercent > 100 || $minpercent < 0) {
die("Argument minpercent must be in range 0...100.\n");
}
} else {
$minpercent = 7;
}
$text = strip_tags(file_get_contents($argv[1]));
$words = preg_split('/(\b|\s|\p{P})+/', $text);
$counters = array();
foreach ($words as $w) {
if ($w == '') continue;
$w = strtoupper($w);
if (!isset($counters[$w])) {
$counters[$w] = 1;
} else {
$counters[$w]++;
}
}
$maxlen = 0;
$factor = 100.0 / count($counters);
foreach ($counters as $w => $n) {
$counters[$w] *= $factor;
if (strlen($w) > $maxlen) {
$maxlen = strlen($w);
}
}
arsort($counters);
foreach ($counters as $w => $p) {
if ($p >= $minpercent) {
printf("%s%s%.2f%%\n", $w, str_repeat('.', $maxlen - strlen($w)
+ 3), $p);
}
}