<html>
<head>
<title>Text Twist Unscrambler</title>
<META NAME="keywords" CONTENT="Text,Twist,Text Twist,Unscramble,Free,Source,php">
</head>
<body>
<font face="arial,helvetica" size="3">
<?
if($_POST['l']) {
$time_start = microtime(true);
$l = $_POST['l'];
$len = strlen($l);
$a = array('a' => 1, 'b' => 1, 'c' => 1, 'd' => 1, 'e' => 1, 'f' => 1, 'g' => 1, 'h' => 1, 'i' => 1, 'j' => 1, 'k' => 1, 'l' => 1, 'm' => 1, 'n' => 1, 'o' => 1, 'p' => 1, 'q' => 1, 'r' => 1, 's' => 1, 't' => 1, 'u' => 1, 'v' => 1, 'w' => 1, 'x' => 1, 'y' => 1, 'z' => 1);
function contains($word) {
$wlen = strlen($word);
if($wlen < 3 || $wlen > 10) return FALSE;
for($i = 0; $i < $wlen; $i++) {
$w[$i] = $word[$i];
}
$b = $GLOBALS['b'];
foreach($b as $n => $c) {
foreach($w as $k => $v) {
if($v == $c) {
unset($w[$k]);
unset($b[$n]);
break;
}
}
}
//echo "count: ". count($w) ."\n";
if(count($w) > 0) return FALSE;
return TRUE;
}
for($i = 0; $i < $len; $i++) {
$b[$i] = $l[$i];
unset($a[$l[$i]]);
}
$e = 'cat scrabble_dictionary.txt';
while(list($k) = each($a)) {
$e .= ' | grep -v '. $k;
}
exec($e, $o);
settype($w, 'array');
foreach($o as $v) {
if(contains($v)) {
$w[] = $v;
}
}
function mycmp($a, $b) {
$ca = strlen($a);
$cb = strlen($b);
if($ca == $cb) return 0;
if($ca > $cb) return 1;
return -1;
}
usort($w, 'mycmp');
foreach($w as $v) {
$c = strlen($v);
if($wc != $c) {
echo "<p>\n";
echo "<b>$c letter words</b><br>";
}
$wc = $c;
echo "$v ";
}
echo "<br><br>\n";
$time_end = microtime(true);
$time = round($time_end - $time_start, 5);
echo "Found ". count($w) ." words in $time seconds\n";
}
?>
<form action="texttwist.php" method="post">
enter scrambled letters and I'll return all word combinations<br>
<input type="text" name="l" value="<?=$l?>" size="20" maxlength="20">
<input type="submit" name="button" value="unscramble">
<input type="button" name="clear" value="clear" onClick="this.form.l.value='';">
</form><p>
<a href=texttwist.phps>php source</a>
- it's kinda ugly, but it's fast<p>
<a href=/>back to my page</a>
</body>
</html>