summaryrefslogtreecommitdiffstats
path: root/index.php
diff options
context:
space:
mode:
authorMaksymilian Jopek <maks@jopek.eu>2022-02-15 20:42:04 +0100
committerMaksymilian Jopek <maks@jopek.eu>2022-02-15 20:42:04 +0100
commitd1dcd0b49010bba31e44859e0d1d76abb7fb20fc (patch)
tree9b0ef2f20679d708933de9876855b458249f1a08 /index.php
downloadalahelo-madio-d1dcd0b49010bba31e44859e0d1d76abb7fb20fc.tar.gz
alahelo-madio-d1dcd0b49010bba31e44859e0d1d76abb7fb20fc.tar.zst
alahelo-madio-d1dcd0b49010bba31e44859e0d1d76abb7fb20fc.zip
Initial commit - v1.0.0
Diffstat (limited to 'index.php')
-rw-r--r--index.php24
1 files changed, 24 insertions, 0 deletions
diff --git a/index.php b/index.php
new file mode 100644
index 0000000..a67bd26
--- /dev/null
+++ b/index.php
@@ -0,0 +1,24 @@
+<?php
+header("Access-Control-Allow-Origin: *");
+header("Access-Control-Allow-Headers: Content-Type");
+$method = $_SERVER['REQUEST_METHOD'];
+$xml = simplexml_load_file("./terc.xml");
+// var_dump($xml);
+if ($method === "GET") {
+ // $result = $xml->xpath('//row/NAZWA_DOD[text()="województwo"]/ancestor::*/NAZWA/text()');
+ $result = $xml->xpath('//NAZWA_DOD[text()="województwo"]/ancestor::*/NAZWA/text() | //NAZWA_DOD[text()="województwo"]/ancestor::*/WOJ/text()');
+} else if ($method === "POST") {
+ $body = file_get_contents('php://input');
+ // echo $body;
+ // echo '//row/NAZWA[text()="' . $body . '"]/ancestor::*/NAZWA_DOD[contains(text(),"miejs")]/ancestor::*/NAZWA/text()';
+ $result = $xml->xpath('//row/WOJ[text()="' . $body . '"]/ancestor::*/NAZWA_DOD[contains(text(),"miejs")]/ancestor::*/NAZWA/text()');
+} else {
+ $result = $xml->xpath('//row/NAZWA[text()="ŁÓDZKIE"]/ancestor::*/NAZWA_DOD[contains(text(),"miejs")]/ancestor::*/NAZWA/text()');
+ $result = $xml->xpath('//WOJ[text()="10"]/ancestor::*/NAZWA_DOD[contains(text(),"miejs")]/ancestor::*/NAZWA/text()');
+ $result = $xml->xpath('//NAZWA_DOD[text()="województwo"]/ancestor::*/NAZWA/text() | //NAZWA_DOD[text()="województwo"]/ancestor::*/WOJ/text()');
+}
+$result = array_map(function ($x) {
+ return "$x";
+}, $result);
+echo json_encode($result);
+// print_r($result);