PHP Code:
$lexicon = array('lector','doctor','focus','jocus','districtus','civitatem','adoptare','opera','secundus');
$alphabet = array('V=aeiou','C=ptcqbdgmnlrhs','F=ie','B=ou','S=ptc','Z=bdg');
$rules = array('s//_#','m//_#','e//Vr_#','v//V_V','u/o/_#','gn/nh/_','c/i/F_t','c/u/B_t','p//V_t','ii/i/_','e//C_rV');
# converting alphabet array into wanted key => value
foreach($alphabet as $alpha) {
$a[] = explode("=",$alpha);
}
$alphabet = array();
foreach($a as $b => $c) {
$alphabet[$c[0]] = trim($c[1]);
}
# rules
foreach($rules as $rule) {
$r[] = explode("/",$rule);
}
$rules = array();
foreach($r as $s => $t) {
$rules[] = array("find" => $t[0], "replace" => $t[1], "condition" => $t[2]);
}
$find = "";
$replace = "";
foreach($rules as $rule) {
$find = trim($rule['find']);
printR("FIND: $find");
$replace = trim($rule['replace']);
printR("REPLACE: $replace");
$condition = trim($rule['condition']);
printR("CONDITION: $condition");
# replace # with $ to indicate end of line
$condition = preg_replace('([a-z])','($0)',$condition);
$condition = str_replace("_#","($find)\$",$condition);
$condition = str_replace("#_","^($find)",$condition);
$condition = str_replace("_","($find)",$condition);
foreach($alphabet as $key => $alpha) {
// $find = str_replace($key,"([$alpha])",$find);
// $replace = str_replace($key,"([$alpha])",$replace);
$condition = str_replace($key,"([$alpha])",$condition);
}
$condition = "/$condition/";
printR("REGEX: $condition");
foreach($lexicon as $key => $word) {
$match = preg_match($condition,$word,$matches);
if(count($matches)) {
printR("\n\n");
printR($word);
printR($matches);
// $word = preg_replace($condition,$replace,$word);
// printR($word);
}
// $lexicon[$key] = $word;
}
printR("\n\n\n");
}
Commented out the stuff that I haven't used yet or that isn't working. printR is the only custom function, and all it is is a quick modification of print_r that wraps the printed text in <pre> tags.
Bookmarks