letter-herhaling-herkenning
Gesponsorde koppelingen
PHP script bestanden
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
// string, maxlength strings
function RepeatLetter ($string, $maxlength)
{
// check if string is not longer then max
if (strlen($string) <= $maxlength && !empty($string))
{
// put letters in an array
for ($i = 0; $i < strlen($string); $i++)
$letters[$i] = $string[$i];
// set repeat counter to 1
$repeat = 1;
// loop through all letters
foreach($letters as $value)
{
if (empty($save_value))
$save_value = $value;
else
{
// if saved letter is the same as the previous letter,
// count the repeat counter
if ($save_value == $value)
$repeat++;
// save the new letter
else
$save_value = $value;
}
}
// return the number a letter is repeated
return $repeat;
}
}
?>
// string, maxlength strings
function RepeatLetter ($string, $maxlength)
{
// check if string is not longer then max
if (strlen($string) <= $maxlength && !empty($string))
{
// put letters in an array
for ($i = 0; $i < strlen($string); $i++)
$letters[$i] = $string[$i];
// set repeat counter to 1
$repeat = 1;
// loop through all letters
foreach($letters as $value)
{
if (empty($save_value))
$save_value = $value;
else
{
// if saved letter is the same as the previous letter,
// count the repeat counter
if ($save_value == $value)
$repeat++;
// save the new letter
else
$save_value = $value;
}
}
// return the number a letter is repeated
return $repeat;
}
}
?>