PHP 7 Script to Find All Words Which are Greater than Given Length K in String
<?php
// PHP program to find all $
// which are greater than given length k
// function find string greater than
// length k
function string_k($s, $k)
{
// create the empty string
$w = "";
// iterate the loop till every space
for($i = 0; $i < strlen($s); $i++)
{
if($s[$i] != ' ')
// append this sub $in $w
$w = $w.$s[$i];
else {
// if length of current sub
// $w is greater than
// k then print
if(strlen($w) > $k)
echo ($w." ");
$w = "";
}
}
}
// Driver code
$s = "geek for geeks";
$k = 3;
$s = $s . " ";
string_k($s, $k);
// This code is contributed by
// Manish Shaw (manishshaw1)
?>