-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTranslator.php
More file actions
63 lines (62 loc) · 1.88 KB
/
Translator.php
File metadata and controls
63 lines (62 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE html>
<?php
$t = @$_GET["translate"];
?>
<html>
<head>
<title>Simple Translator</title>
<script src="main.js"></script>
<link rel="stylesheet" href="custom.css">
</head>
<body>
<div class="container text-center mt-5">
<form method="GET">
<div class="row form-group mx-sm-3 mb-2">
<input type="text" class="col-9 form-control" name="translate" value="<?php echo $t;?>">
<input type="submit" class="col-3 btn btn-primary" value="translate">
</form>
</div>
</body>
</html>
<?php
// Arrays
$all_words = array();
$sentence = array();
// word
$input = @$_GET["translate"];
$word_count = str_word_count($input);
//Get all words in word file
$fn = fopen("Indo-English.txt","r");
while(! feof($fn)) {
$result = fgets($fn);
$split_words = preg_split ("[\s]", $result);
for ($i = 0; $i < count($split_words); $i++) {
array_push($all_words, $split_words[$i]);
}
}
fclose($fn);
if ($word_count > 1){
$sentence = preg_split ("[\s]", $input);
for ($i = 0; $i < count($sentence); $i++) {
$word = array_search($sentence[$i], $all_words);
$translate = indo_to_english($word);
$translated_word = $all_words[$translate];
echo " ".$translated_word;
}
} else {
// find word
$word = array_search("$input", $all_words);
if($word == null){
echo "$input";
} else {
$translate = indo_to_english($word);
$translated_word = $all_words[$translate];
echo "</br>Translated word: ".$translated_word;
}
}
// functions
function indo_to_english($tword){
$translated = $tword + 1;
return $translated;
}
?>