From bf7852bccce954aff2d7c94161f4d301a0f29684 Mon Sep 17 00:00:00 2001 From: Maksymilian Jopek Date: Wed, 16 Mar 2022 23:20:59 +0100 Subject: Initial commit w/ v1.0.0 --- src/data.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/data.php (limited to 'src/data.php') diff --git a/src/data.php b/src/data.php new file mode 100644 index 0000000..aaf9d88 --- /dev/null +++ b/src/data.php @@ -0,0 +1,38 @@ +getElementsByTagName($name)->item(0)->nodeValue; +} +function get_doc(): DOMDocument +{ + $doc = new DOMDocument(); + $path = "/home/maks/school/clientApps/mlos/src/db.xml"; + $doc->load($path); + return $doc; +} +function get_data(): array +{ + $doc = get_doc(); + $out = []; + $games = $doc->getElementsByTagName("game"); + $i = 0; + while ($game = $games->item($i++)) { + $out[] = [ + "id" => $game->getAttribute("id"), + "order" => $game->getAttribute("order"), + "name" => get_node_value($game, "name"), + "thumbnail" => get_node_value($game, "thumbnail"), + "author" => get_node_value($game, "author"), + "magazine" => get_node_value($game, "magazine"), + ]; + } + usort($out, function ($a, $b) { + return $a["order"] - $b["order"]; + }); + return [$out, $doc->getElementsByTagName("count")->item(0)->nodeValue]; +} + +$doc = get_doc(); +$xpath = new DOMXpath($doc); +$game = $xpath->query('//game[@id="2"]/name')->item(0); +// var_dump($game); -- cgit v1.3.1