wf.php
<?php
if ($_POST['tegen']) {
$tegen=$_POST['tegen'];
}
else if($_COOKIE['tegen']){
$tegen = $_COOKIE['tegen'];
}
else{
$tegen ='JohnDoe';
}
//print_r($_COOKIE);
if ($_POST['letters']) {
$letters = strtolower($_POST['letters']);
setcookie($tegen,$letters,time()+604800);
setcookie('tegen',$tegen,time()+604800);
}
else if($_COOKIE['tegen']){
$letters = $_COOKIE[$tegen];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Wordfeudteller</title>
</head>
<body>
<div style='float:left;width:300px;'>
<form method='post' id='form'>
Tegenstander:<br><input type='text' name='tegen' id='tegen' value='<?php echo $tegen;?>'>
<br><textarea name='letters' id='letters' cols=15 rows=18 style='text-transform:uppercase ;font-family:courier new;font-size:20px'>
<?php
if($letters){
echo $letters;
}
else{
?><?php
}
?>
</textarea>
<p><input type='submit' name='submit' value='Verzenden'>
<input type='button' onclick="document.getElementById('letters').innerHTML='';document.getElementById('tegen').value=''" name='reset' value='Reset'></p>
</form>
</div>
<?php
$wfletters = array('?' => 2,'A' => 7, 'B' => 2, 'C' => 2, 'D' => 5, 'E' => 18, 'F' => 2, 'G' => 3, 'H' => 2, 'I' => 4, 'J' => 2, 'K' => 3, 'L' => 3, 'M' => 3, 'N' => 11, 'O' => 6, 'P' => 2, 'Q' => 1, 'R' => 5, 'S' => 5, 'T' => 5, 'U' => 3, 'V' => 2, 'W' => 2, 'X' => 1, 'Y' => 1, 'Z' => 2);
if ($_POST['letters']) {
$letters = str_replace(" ","",strtolower($_POST['letters']));
$freq = count_chars($letters, 1);
arsort($freq);
$letters = [];
foreach ($freq as $i => $val) {
$letter = strtoupper(chr($i));
if (preg_match('/[A-Z]/', $letter) || $letter == "?") {
$letters[$letter] = $val;
}
}
ksort($letters);
foreach ($letters as $letter => $aantal) {
$over =$wfletters[$letter]-$aantal;
if($over!=0){
for($i=0;$i<$over;$i++){
echo "$letter";
}
echo " ";
}
}
// print_r($letters);
foreach($wfletters as $letter => $aantal){
if(!array_key_exists($letter, $letters)){
for($i=0;$i< $aantal;$i++){
echo "$letter";
}
echo " ";
}
}
//
}
?>
</body>
</html>
Resultaat
Made by Thijs Aarnoudse