Se importa la función parsecfg() creada por jem
authorJem <joseemiliomori@wikimedia.es>
Mon, 21 May 2018 20:23:50 +0000 (22:23 +0200)
committerPlatonides <platonides@gmail.com>
Mon, 21 May 2018 21:28:21 +0000 (23:28 +0200)
html/wiki.php [new file with mode: 0644]

diff --git a/html/wiki.php b/html/wiki.php
new file mode 100644 (file)
index 0000000..35c6c3a
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+
+function parsecfg ($F) {                        # Se admiten matrices numéricas (guardadas como m = v1:v2...) o asociativas (guardadas como m.c1 = v1\\m.c2 = v2...)
+        foreach (file ($F, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $L) {
+                list ($C, $V) = preg_split ("/\s*=\s*/", $L, 2);
+                if (strpos ($C, ".") !== FALSE) {
+                        $CC = explode (".", $C, 2);             # Necesario limitar a 2 por si hay puntos en la clave
+                        $D[$CC[0]][$CC[1]] = $V;
+                } else {
+                        $D[$C] = strpos ($V, ";") !== FALSE && strpos ($V, "[[") === FALSE && strpos ($V, "<") === FALSE ? explode (";", $V) : $V;
+                        if (! end ($D[$C])) array_pop ($D[$C]);         # Eliminar último elemento vacío (normalmente por ; final que fuerza array)
+                }
+        }
+        return $D;
+}