From 3b0517161f151f97cd12aa16badab5fec4c59cf1 Mon Sep 17 00:00:00 2001 From: stuzer05 Date: Tue, 12 Dec 2023 11:45:57 +0200 Subject: [PATCH] Add str to php array tool --- api/php/data_to_php_array.php | 58 +++++++++++++++++++++++++++++++++ src/components/Sidebar.vue | 1 + src/router/index.js | 5 +++ src/views/StrToPHPArray.vue | 61 +++++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 api/php/data_to_php_array.php create mode 100644 src/views/StrToPHPArray.vue diff --git a/api/php/data_to_php_array.php b/api/php/data_to_php_array.php new file mode 100644 index 0000000..ca26990 --- /dev/null +++ b/api/php/data_to_php_array.php @@ -0,0 +1,58 @@ + \[\n\s+\],\n#', "=> [],\n", $dump); // Empties + + if (gettype($data) == 'object') { // Deal with object states + $dump = str_replace('__set_state(array(', '__set_state([', $dump); + $dump = preg_replace('#\)\)$#', "])", $dump); + } else { + $dump = preg_replace('#\)$#', "]", $dump); + } + + if ($return===true) { + return $dump; + } else { + echo $dump; + } +} + +switch ($input['mode']) { + case 'json': + echo var_export_short(@json_decode($data, true)); + break; + default: + echo var_export_short(explode(empty($data_delimiter) ? "\n" : $data_delimiter, $data)); + break; +} \ No newline at end of file diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue index d624521..1ce399b 100644 --- a/src/components/Sidebar.vue +++ b/src/components/Sidebar.vue @@ -34,6 +34,7 @@ export default { 'str_sort_lines': 'Str sort lines', 'str_to_lower_upper': 'Str to lower/upper', 'str_remove_duplicate_lines': 'Str remove duplicate lines', + 'str_to_php_array': 'Str to PHP array', 'url_encode_decode': 'URL encode/decode', }, 'SQL': { diff --git a/src/router/index.js b/src/router/index.js index 31adb45..e664d05 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -35,6 +35,11 @@ const router = createRouter({ name: 'str_remove_duplicate_lines', component: () => import('../views/StrRemoveDuplicateLines.vue'), }, + { + path: '/str_to_php_array', + name: 'str_to_php_array', + component: () => import('../views/StrToPHPArray.vue'), + }, { path: '/fix_ru_en_keyboard', name: 'fix_ru_en_keyboard', diff --git a/src/views/StrToPHPArray.vue b/src/views/StrToPHPArray.vue new file mode 100644 index 0000000..a86e205 --- /dev/null +++ b/src/views/StrToPHPArray.vue @@ -0,0 +1,61 @@ + + + + + \ No newline at end of file