$text_lenght = 3;
$charset = 'abc';
$charset_length = strlen($charset);
function recurse($width, $position, $base_string)
{
global $text_lenght, $charset, $charset_length;
for ($i = 0; $i < $charset_length; ++$i) {
if ($position < $width - 1) {
recurse($width, $position + 1, $base_string . $charset[$i]);
}
if (strlen($base_string . $charset[$i]) <= $text_lenght) {
echo $base_string . $charset[$i].'</br>';
}
}
}
recurse($text_lenght, 0, '');