Example:
a
aaa
aaaaa
aaa
aa
If given length is 3 then it should show:
aaa
aaa
I have:
$words = explode(" ", $_POST['txt']);
for ($i=0; $i<count($words); $i++){
echo $words[$i] . " ";
Can this be done with foreach?
Example:
a
aaa
aaaaa
aaa
aa
If given length is 3 then it should show:
aaa
aaa
I have:
$words = explode(" ", $_POST['txt']);
for ($i=0; $i<count($words); $i++){
echo $words[$i] . " ";
Can this be done with foreach?
$words = explode(" ", $_POST['txt']);
$length = 3;
foreach($words as $word) {
// mb_strlen to take multibyte characters into account
if(mb_strlen($word) == $length) {
echo $word . "
";
}
}
Maybe?