-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparser.php
More file actions
73 lines (71 loc) · 2.55 KB
/
Copy pathparser.php
File metadata and controls
73 lines (71 loc) · 2.55 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
64
65
66
67
68
69
70
71
72
73
<?php
// Max Base
// https://github.com/BaseMax/BookDeweyList
$data=file_get_contents("input-normal.html");
$finalOutput=[];
$persianFile=file_get_contents("names-fa.txt");
$persianLines=explode("\n", $persianFile);
$englishFile=file_get_contents("names-en.txt");
$englishLines=explode("\n", $englishFile);
function translate($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 toEN($input) {
return strtr($input, array('۰'=>'0', '۱'=>'1', '۲'=>'2', '۳'=>'3', '۴'=>'4', '۵'=>'5', '۶'=>'6', '۷'=>'7', '۸'=>'8', '۹'=>'9', '٠'=>'0', '١'=>'1', '٢'=>'2', '٣'=>'3', '٤'=>'4', '٥'=>'5', '٦'=>'6', '٧'=>'7', '٨'=>'8', '٩'=>'9'));
}
$pattern='/<!-- begin -->\n<h2>(?<title>[^\<]+)<\/h2>[\n\s]+<ul>(?<content>.*?)<\/ul>\n<!-- end -->/is';
preg_match_all($pattern, $data, $output);
print_r($output["content"]);
foreach($output["content"] as $x=>$item) {
$category=[];
$category["title"]=$output["title"][$x];
$name=$category["title"];
// ۰۱۲۳۴۵۶۷۸۹
$category["code"]=mb_substr($output["title"][$x], 4, 3);
$category["codeEN"]=toEN($category["code"]);
$name=mb_substr($name, mb_strlen("ردهٔ ۰۰۰ –"));
// $name=preg_replace('/ردهٔ ( {***/۰۱۲۳۴۵۶۷۸۹/***} ) – /i', "", $name);
$category["name"]=$name;
$category["nameEN"]=translate($category["name"]);
$category["children"]=[];
$pattern='/<li><b>(?<title>[^\<]+)<\/b>[\n\s]+<ul>(?<content>.*?)<\/ul>/is';
preg_match_all($pattern, $item, $result);
print_r($result);
$pattern='/<li>(?<title>[^\<]+)<\/li>/si';
foreach($result["content"] as $y=>$itemList) {
$itm=[];
$itm["title"]=$result["title"][$y];
$itm["code"]=mb_substr($result["title"][$y], 0, 3);
$itm["codeEN"]=toEN($itm["code"]);
$itm["name"]=mb_substr($result["title"][$y], 4);
$itm["nameEN"]=translate($itm["name"]);
$itm["children"]=[];
preg_match_all($pattern, $itemList, $items);
foreach($items["title"] as $itemLowLevel) {
$downLevel=[];
$downLevel["title"]=$itemLowLevel;
$downLevel["code"]=mb_substr($itemLowLevel, 0, 3);
$downLevel["codeEN"]=toEN($downLevel["code"]);
$downLevel["name"]=mb_substr($itemLowLevel, 4);
$downLevel["nameEN"]=translate($downLevel["name"]);
$itm["children"][]=$downLevel;
}
// print_r($items);
$category["children"][]=$itm;
}
// print_r($category);
$finalOutput[]=$category;
// exit();
}
print_r($finalOutput);
file_put_contents("output.json", json_encode($finalOutput));