From e99e92dda4fb9fdf4e06007504908a808b598d62 Mon Sep 17 00:00:00 2001 From: stuzer05 Date: Tue, 20 Aug 2024 22:00:04 +0300 Subject: [PATCH] Add php serialize tool --- api/php/php_serialize.php | 62 +++++++++++++++++++++++++++++++++++++ src/components/Sidebar.vue | 1 + src/router/index.js | 5 +++ src/views/PHPSerialize.vue | 63 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 131 insertions(+) create mode 100644 api/php/php_serialize.php create mode 100644 src/views/PHPSerialize.vue diff --git a/api/php/php_serialize.php b/api/php/php_serialize.php new file mode 100644 index 0000000..fccbe07 --- /dev/null +++ b/api/php/php_serialize.php @@ -0,0 +1,62 @@ + \[\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 'serialize': + $data = ''; + + // try any vaue + try { + eval("\$data = " . $input['data'] . ";"); + echo serialize($data); + } catch (Throwable $e) { + + try { + eval("\$data = '" . addslashes($input['data']) . "';"); + echo serialize($data); + } catch (Throwable $e) { + echo 'err: invalid syntax, use $val = [your text];'; + } + } + + break; + default: + $data = $input['data']; + $result = unserialize($data); + + if ($result) { + if (is_string($result)) { + echo trim(var_export_short($result), "'"); + } else { + echo var_export_short($result); + } + } else { + echo 'err: invalid syntax'; + } + + break; +} diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue index 0c8a7f2..8d901cd 100644 --- a/src/components/Sidebar.vue +++ b/src/components/Sidebar.vue @@ -60,6 +60,7 @@ export default { 'PHP': { 'str_to_php_array': 'Str to PHP array', 'php_array_to_json': 'PHP array to Json', + 'php_serialize': 'PHP serialize', }, 'GO': { 'go_json_to_struct': 'JSON to Go struct', diff --git a/src/router/index.js b/src/router/index.js index eb8419b..e3ac576 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -95,6 +95,11 @@ const router = createRouter({ name: 'php_array_to_json', component: () => import('../views/PHPArrayToJson.vue'), }, + { + path: '/php_serialize', + name: 'php_serialize', + component: () => import('../views/PHPSerialize.vue'), + }, { path: '/fix_ru_en_keyboard', name: 'fix_ru_en_keyboard', diff --git a/src/views/PHPSerialize.vue b/src/views/PHPSerialize.vue new file mode 100644 index 0000000..683f01b --- /dev/null +++ b/src/views/PHPSerialize.vue @@ -0,0 +1,63 @@ + + + + + \ No newline at end of file