-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjson-reader.php
59 lines (55 loc) · 1.44 KB
/
json-reader.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
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
<?php
// Max Base
// https://github.com/BaseMax/BookDeweyList
$dataFile=file_get_contents("output.json");
$data=json_decode($dataFile, true);
// print_r($data);
/*
readJson($data);
function readJson($data) {
foreach($data as $item) {
if(isset($item["name"])) {
print $item["name"]."\n";
file_put_contents("names-fa.txt", $item["name"]."\n", FILE_APPEND);
}
if(isset($item["children"])) {
readJson($item["children"]);
}
}
}
*/
$persianFile=file_get_contents("names-fa.txt");
$persianLines=explode("\n", $persianFile);
$englishFile=file_get_contents("names-en.txt");
$englishLines=explode("\n", $englishFile);
readJson($data);
function findWord($fa) {
global $persianLines;
global $englishLines;
// print_r($persianLines);
// print_r($englishLines);
// exit();
foreach($persianLines as $i=>$line) {
if($line == $fa) {
return $englishLines[$i];
}
}
return $fa;
}
function readJson($data) {
global $dataFile;
// file_put_contents("names-fa.txt", "");
foreach($data as $item) {
if(isset($item["name"])) {
// file_put_contents("names-fa.txt", $item["name"]."\n", FILE_APPEND);
$enW=findWord($item["name"]);
// $dataFile=str_replace(utf8_encode($item["name"]), utf8_encode($enW), $dataFile);
$dataFile=str_replace(($item["name"]), ($enW), $dataFile);
print $item["name"]." => " . $enW . "\n";
}
if(isset($item["children"])) {
readJson($item["children"]);
}
}
}
file_put_contents("output-en.json", $dataFile);