
hello,
i want a script that can generate all the all words from given alphabets
for example
if i have three alphabets A,B,C
then a script that will generate the words as like below
a
b
ab
bc
ca
ac
abc
cab
bac
acb
i mean all the possible combinations
so please help me in this
thanks

import java.util.*;
public class PermutationExample {
public static void main(String args[]) throws Exception {
Scanner input = new Scanner(System.in);
System.out.print("Enter String: ");
String chars = input.next();
showPattern("", chars);
}
public static void showPattern(String st, String chars) {
if (chars.length() <= 1)
System.out.println(st + chars);
else
for (int i = 0; i < chars.length(); i++) {
try {
String newString = chars.substring(0, i)
+ chars.substring(i + 1);
showPattern(st + chars.charAt(i), newString);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

function permute($str,$i,$n) {
if ($i == $n)
print "$str\n";
else {
for ($j = $i; $j < $n; $j++) {
swap($str,$i,$j);
permute($str, $i+1, $n);
swap($str,$i,$j);
}
}
}
function swap(&$str,$i,$j) {
$temp = $str[$i];
$str[$i] = $str[$j];
$str[$j] = $temp;
}
$str = "hey";
permute($str,0,strlen($str));

$string = "ABC";
$strings = explode(' ', $string);
print_r(concat($strings, ""));
function concat(array $array, $base_string) {
$results = array();
$count = count($array);
$b = 0;
foreach ($array as $key => $elem){
$new_string = $base_string . " " . $elem;
$results[] = $new_string;
$new_array = $array;
unset($new_array[$key]);
$results = array_merge($results, concat ($new_array, $new_string));
}
return $results;
}

function permute($str,$i,$n) {
if ($i == $n)
print "$str\n";
else {
for ($j = $i; $j < $n; $j++) {
swap($str,$i,$j);
permute($str, $i+1, $n);
swap($str,$i,$j);
}
}
}
function swap(&$str,$i,$j) {
$temp = $str[$i];
$str[$i] = $str[$j];
$str[$j] = $temp;
}
$str = "hey";
permute($str,0,strlen($str));
this helps me but there is problem
when i type string hey it generates only this result
(hey hye ehy eyh yeh yhe)
but i want in this way
y e h ye he ey eh eyh yeh hey
i mean all possible worlds that i can make from the given alphabets
these generated words must contain
all single abphabets
all combibation two alphabets
and all combination from three alphabets
i want this script in php
thank