anagram solving problem
Posted: Sat May 20, 2006 12:18 pm
I am creating a php script to solve anagrams for a certain thing. The word list contains 41611 words.
The user enters a word, and the word's letter are arranged alphabetically:
user enters 'tpdcie', the letters are rearranged like this 'cdeipt'.
I have a huge switch statement, like this:With 41611 different cases. This is where the problem begins. If I have fewer cases, like the first 20 (it can probably handle more than that), it works perfectly. But if I have the full switch statement in the php file or having the function in an include, Firefox tries to download the file, and I get no output. If I echo something at the start of the php file, I don't see it.
This is the main php file:
v4.inc:
Can anybody give me a better method to use, or tell me why I can't use my current one? Or just tell me anything generally wrong. Thanks
The user enters a word, and the word's letter are arranged alphabetically:
user enters 'tpdcie', the letters are rearranged like this 'cdeipt'.
I have a huge switch statement, like this:
Code: Select all
function wordo($input)
{
switch ($input) {
case 'ddeenp': $rt = 'depend'; break;
case 'dddeeenp': $rt = 'depended'; break;
case 'ddeenps': $rt = 'depends'; break;
case 'cdeipt': $rt = 'depict'; break;
case 'cddeeipt': $rt = 'depicted'; break;
case 'cdeipst': $rt = 'depicts'; break;
case 'adeelnp': $rt = 'deplane'; break;
case 'addeelnp': $rt = 'deplaned'; break;
case 'adeelnps': $rt = 'deplanes'; break;
}
return $rt;
}This is the main php file:
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php
//echo "start";
$t = $HTTP_GET_VARS[a];
if ($t != "")
{
$retstr = "";
for ($i = 0; $i <= strlen($t)-1; $i++) {
$retstr .= $t{$i}." ";
}
$t = $retstr;
$arr = explode(" ",$t);
sort($arr);
$ec = implode("", $arr);
//echo $ec;
include 'v4.inc';
echo wordo($ec);
}
?>
</body>
</html>Code: Select all
<?php
function wordo($input)
{
switch ($input) {
//.. lots of other cases..
case 'ddeenp': $rt = 'depend'; break;
case 'dddeeenp': $rt = 'depended'; break;
case 'ddeenps': $rt = 'depends'; break;
case 'cdeipt': $rt = 'depict'; break;
case 'cddeeipt': $rt = 'depicted'; break;
case 'cdeipst': $rt = 'depicts'; break;
case 'adeelnp': $rt = 'deplane'; break;
case 'addeelnp': $rt = 'deplaned'; break;
case 'adeelnps': $rt = 'deplanes'; break;
//.. lots of other cases..
}
return $rt;
}
?>