This code will work for all modern PHP versions (including PHP 5, PHP 7, and PHP 8).
index.php
PHP
x
37
37
1
<?php
2
// PHP program to find all words
3
// which are greater than given length $x
4
5
// function find string greater than
6
// length $x
7
function string_x($s, $x)
8
{
9
10
// create the empty string
11
$w = "";
12
13
// iterate the loop till every space
14
for($i = 0; $i < strlen($s); $i++)
15
{
16
if($s[$i] != ' ')
17
18
// append this sub string in $w
19
$w = $w.$s[$i];
20
else {
21
22
// if length of current sub string
23
// $w is greater than
24
// $x then print
25
if(strlen($w) > $x)
26
echo ($w."<br />");
27
$w = "";
28
}
29
}
30
}
31
32
// Provide function parameters and execute the function
33
$s = "Edopedia - Become a Better Software Developer";
34
$x = 7;
35
$s = $s . " ";
36
string_x($s, $x);
37
?>
Output
Edopedia
Software
Developer