Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $lines = explode("n", $configText);
- $tree = [];
- $currentKey = null;
- foreach ($lines as $row) {
- if (empty($row)) {
- continue;
- } elseif (preg_match('/^s*[(.*?)]s*$/', $row, $matches)) {
- $currentKey = trim($matches[1]);
- } elseif ($currentKey && preg_match('/^(w+)=(.*)/', $row, $matches)) {
- $currentProperty = trim($matches[1]);
- $currentValues = trim($matches[2]);
- $values = [];
- if (preg_match_all('/(w+)=/', $currentValues, $matches)) {
- $values = preg_split('/(w+)=/', $currentValues);
- $values = array_map('trim', $values);
- if (empty($values[0])) {
- unset($values[0]);
- } else {
- array_unshift($matches[1], "");
- }
- $values = array_combine($matches[1], $values);
- } else {
- $values[""] = $currentValues;
- }
- $tree[$currentKey][$currentProperty] = [
- 'value' => $currentValues,
- 'params' => $values,
- ];
- } else {
- throw new Exception('Unexpected scenario');
- }
- }
- print_r($tree);
Add Comment
Please, Sign In to add comment