1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- /**
- * dolphin. Collection of useful PHP skeletons.
- * Copyright (C) 2022 Johannes 'Banana' Keßler
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
- *
- * You should have received a copy of the
- * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
- * along with this program. If not, see http://www.sun.com/cddl/cddl.html
- */
- /**
- * out.txt: lines of a unix directory like structure
- * out.json: The json of the $out array
- */
- $out = array();
- $_w = &$out;
- $handle = fopen("paths.txt", "r");
- $count = 0; // debug only
- if ($handle) {
- while (($line = fgets($handle)) !== false) {
- $_t = explode("/", $line);
-
- foreach ($_t as $value) {
- $value = trim($value);
- if(empty($value)) continue;
- if(!isset($_w[$value])) {
- $_w[$value] = array("name" => $value, "children" => array());
- $_w = &$_w[$value]["children"];
- }
- else {
- $_w = &$_w[$value]["children"];
- }
- }
- $_w = &$out;
- /*
- $count++;
- if($count > 10) {
- var_dump($out);
- exit();
- }
- */
- }
- fclose($handle);
- } else {
- // error opening the file.
- echo "error opening the file";
- }
- //var_dump($out);
- file_put_contents("out.json", json_encode($out, JSON_PRETTY_PRINT));
|