The Real cha0s
Order emerges out of cha0s :)

PHP anagram finder!

This code will find an anagram on a Linux or Mac machine that has a dictionary installed! Nothing big, but have fun!

#!/usr/bin/php
<?

$word = $argv[1];

$greps = 'grep ' . implode(" | grep ", str_split($word));

$length = strlen($word);

$candidates = explode("\n", `cat /usr/share/dict/words | $greps | egrep '^[a-z]{{$length}}$'`);

print implode("\n", array_filter($candidates, function($e) use ($word) {

  $w = str_split($word);
  $c = str_split($e);

  asort($w);
  asort($c);

  return implode('', $w) == implode('', $c);
})) . "\n";
$ anagram lestab
ablest
bleats
stable
tables

^^ Yay!