Skip to content

Instantly share code, notes, and snippets.

@sarim
Created June 17, 2012 13:31
Show Gist options
  • Save sarim/2944571 to your computer and use it in GitHub Desktop.
Save sarim/2944571 to your computer and use it in GitHub Desktop.
Converting raw dict text to json object
<?php
//This script will convert the avro autocorrect dict to json. Rifat bro already did it using textmate manually, but my approach is artistic :D
//Get the raw dict from github
$raw = file_get_contents("https://raw.github.com/omicronlab/Avro-Keyboard/master/Keyboard%20and%20Spell%20checker/autodict.dct");
//breaking the lines
$lines = explode("\n",$raw);
$arr = array();
//looping the lines
foreach ($lines as $line) {
//ignoring the comments (on top)
if (substr($line,0,1) != '/') {
list($search_word,$replace_word) = explode(" ",$line);
$arr[$search_word] = $replace_word;
}
}
//finally echoing json object
echo(json_encode($arr));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment