A very simple php script to count the numbers from each line. Input from a textarea. I know that is quite useless but I occasionally need it to make a few counts.
You can change the delimiter (\n in this case) and use something else like a comma or a pipe (, | / \) and so on.
<?php
$datanr = empty($_POST['datanr']) ? 0 : $_POST['datanr'];
$arrnumbers = explode("\n",$datanr );
$totalnr = 0;
foreach( $arrnumbers as $singlenr){
if(is_numeric(trim($singlenr))){
$totalnr += trim($singlenr);
echo 'nr.: ' . $singlenr . ' - sub: ' . $totalnr .'<br>';
}
}
echo '<form method="POST" name="counter.php"><textarea name="datanr"></textarea><input type="submit" ></form><br>';
echo 'total: ' . $totalnr . '<br>';
?>
Comments
Post a Comment