-
Notifications
You must be signed in to change notification settings - Fork 0
/
getKeyValPair.php
33 lines (31 loc) · 989 Bytes
/
getKeyValPair.php
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
<?php
$FILENAME = "SpanishEnglishAudio.txt";
//printText($FILENAME);
getNWords($FILENAME, 10);
function printText($filename) {
$fh = fopen($filename, "r");
while (!feof($fh)) {
$line = fgets($fh, 99);
$words = explode("#", $line);
echo $words[0] . " ---> " . $words[1] . '--->' . $words[2] . '<br />';
}
}
function getNWords($filename, $no_words) {
$fh = file($filename);
shuffle($fh);
$keys = array_rand($fh, $no_words);
$words = array();
foreach ($keys as $key) {
//echo $fh[$key];
$word = array();
$line = explode("#", $fh[$key]);
//$words[$pair[0]] = rtrim($pair[1]);
$word['sp'] = $line[0];
$word['en'] = rtrim($line[1]);
$word['link'] = rtrim($line[2]);
array_push($words, $word);
}
echo json_encode($words);
}
//get a key/val and return it
?>