<?
header("Content-Type: text/html; charset=utf-8");
$end_engword=$_REQUEST['lookup'];
$eng_word = chr(10);
$eng_word .= $end_engword;
$content = file_get_contents('anhviet109K.index');
$content2 = file_get_contents('anhviet109K.dict');
$head = "";
$main_content = "";
if ($content !== false) {
$pos_of_word = strpos($content,$eng_word);
if($pos_of_word<1)
{
echo "Không tìm thấy từ <b>[".$end_engword."]</b> trong VN4000 Dictionary!";
exit();
}
$hor_tab = chr(9);
$end_trans = chr(10);
$pos_of_tab1 = strpos($content,$hor_tab,$pos_of_word);
$pos_of_tab2 = strpos($content,$hor_tab,$pos_of_tab1+1);
$end_of_trans = strpos($content,$end_trans,$pos_of_tab2+1);
$long_of_second_para = $pos_of_tab2-$pos_of_tab1-1;
$long_of_third_para = $end_of_trans-$pos_of_tab2-1;
$name_of_word = $eng_word;
$begin_of_wordmean = substr($content,$pos_of_tab1+1,$long_of_second_para);
$long_of_wordmean = substr($content,$pos_of_tab2+1,$long_of_third_para);
$begin_of_wordmean_dec = GetDemicalValue ($begin_of_wordmean);
$long_of_wordmean_dec = GetDemicalValue ($long_of_wordmean);
if ($content2 !== false) {
$content_mean = substr($content2,$begin_of_wordmean_dec,$long_of_wordmean_dec);
$new_line_replace = nl2br($content_mean);
$star_add_replace = str_replace('*','*#',$new_line_replace);
$pieces = explode('*', $star_add_replace);
$sie_array = sizeof($pieces);
$new_line_replace2 = array();
$new_line_replace3 = array();
$new_line_replace4 = array();
$new_line_replace5 = array();
$new_line_replace6 = array();
$new_line_replace7 = array();
$pos_idioms = array();
$add_replace = str_replace('@','<B>',$pieces[0]);
$head .= "<font color='red'>".$add_replace."</font>";
for($i = 1; $i<$sie_array; $i++)
{
$new_line_replace2[$i] = str_replace('#','</B><DT><H3>',$pieces[$i]);
$new_line_replace3[$i] = str_replace('-','</H3><DD><B>-</B>',$new_line_replace2[$i]);
$new_line_replace4[$i] = str_replace('=','<DD><DD><LI>',$new_line_replace3[$i]);
$new_line_replace5[$i] = str_replace('+',':',$new_line_replace4[$i]);
$pos_idioms[$i] = strpos($new_line_replace5[$i],'!');
if($pos_idioms[$i]>1)
{
$new_line_replace6[$i] = substr_replace($new_line_replace5[$i],'<font color=\"#0000FF\"><B>Idioms:</B></font><BR>',$pos_idioms[$i],1);
$new_line_replace7[$i] = str_replace('!','',$new_line_replace6[$i]);
}
else
{
$new_line_replace7[$i] = $new_line_replace5[$i];
}
$main_content .= $new_line_replace7[$i]."";
}
$head .= $main_content."";
echo "".$head;
}
else {
echo "Error2";
}
} else {
echo "Error";
}
function GetDemicalValue ($str){
$base64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
$decValue = 0;
$str_length = strlen($str);
for($i = 0; $i<$str_length;$i++){
$char_at = $str{$i};
$pos_of_char = strpos($base64,$char_at);
$decValue = $decValue + pow(64,$str_length-1-$i)* $pos_of_char;
}
return $decValue;
}
?>