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 @@ + + PHP serialize + + + + Data + + + + + Mode + + + serialize + unserialize + + + + + + + Result + + + + + + + \ No newline at end of file