混乱的单词解算器和Word Uncramble代码没有显示所需的结果

I am trying to arrange jumbled word of two letters.

This is inside clock.txt file

to
at
on
of
go
no
so
..
..

This is my html code:

<form action="" method="get">    
    <input type="text" name="word" placeholder="Write jumbled word" maxlength="2" ><br>
    <button>Find</button>
</form>

This is my php code:

if(isset($_GET['word'])){
    $word_one = $_GET['word'] ;
    $word_two = strrev($word_one) ;

    $file = file("clock.txt");

    $i = 0;

    foreach( $file as $value) {    
        if(($value == $word_one ) || ($value == $word_two) ) {
            $result[$i] = $value ;
            $i = $i + 1 ;
        }
    }

    if(isset($result)){
        print_r($result);
    }    
} // end if

This is output:

Array ()

But my desired output is:

Array ( [0] => go )

trim() your value before comparison.

Replace your php code

if(isset($_GET['word'])){
$word_one = trim($_GET['word']) ;
$word_two = strrev($word_one) ;

$file = file("clock.txt");

$i = 0;

foreach( $file as $value){

 if((trim($value) == $word_one ) || (trim($value) == $word_two) ){
  $result[$i] = $value ;
  $i = $i + 1 ;
 }
}



if(isset($result)){
 print_r($result);
}

} // end if

Extra: If you want to make jumbled word solver for more than two character you have to rearrange your jumbled letter using permutation formula. After each permutation, result will be matched with your database words. This process will be done for all possible permutation. After that, you will be able to show your all possible answers.

I did same thing in my site:

http://asifiqbalkhulna.com/