How to get all substrings of a string with PHP

1 Answer

0 votes
$s = "abcde";
            
for ($i = 0; $i < strlen($s); $i++) { 
    for ($j = $i + 1; $j <= strlen($s); $j++) { 
         echo substr($s, $i, $j - $i) . "<br />";
    }
}

   
       
/*
run:
            
a
ab
abc
abcd
abcde
b
bc
bcd
bcde
c
cd
cde
d
de
e
     
*/

 



answered Oct 24, 2019 by avibootz
...