Friday, February 1, 2013

Get all the possible substrings of length

Below is a simple code that will get all the possible substrings with length 2 and above.

<?php
$s='0123456789';

for ($l=2;$l<strlen($s)+1;$l++){
    for ($i=0;$i<(strlen($s)+1-$l);$i++) {
        echo substr ( $s,$i,$l) . "\n";
    }
}
?>
Post a Comment