Add php array to json tool
This commit is contained in:
parent
3b0517161f
commit
99e6523f0c
44
api/php/php_array_to_json.php
Normal file
44
api/php/php_array_to_json.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
// Allow from any origin
|
||||
if (isset($_SERVER['HTTP_ORIGIN'])) {
|
||||
// Decide if the origin in $_SERVER['HTTP_ORIGIN'] is one
|
||||
// you want to allow, and if so:
|
||||
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
|
||||
header('Access-Control-Allow-Credentials: true');
|
||||
header('Access-Control-Max-Age: 86400'); // cache for 1 day
|
||||
}
|
||||
|
||||
// Access-Control headers are received during OPTIONS requests
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
|
||||
|
||||
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
|
||||
// may also be using PUT, PATCH, HEAD etc
|
||||
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
|
||||
|
||||
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
|
||||
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
header('Content-type: text/plain');
|
||||
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
$data = $input['data'];
|
||||
$minify_json = $input['minify_json'];
|
||||
|
||||
try {
|
||||
eval("\$data_array = {$data};");
|
||||
|
||||
$json = @json_encode($data_array, $minify_json ? null : JSON_PRETTY_PRINT);
|
||||
|
||||
echo json_encode([
|
||||
'data' => $json,
|
||||
]);
|
||||
} catch (Throwable $exception) {
|
||||
echo json_encode([
|
||||
'data' => '',
|
||||
]);
|
||||
}
|
@ -35,6 +35,7 @@ export default {
|
||||
'str_to_lower_upper': 'Str to lower/upper',
|
||||
'str_remove_duplicate_lines': 'Str remove duplicate lines',
|
||||
'str_to_php_array': 'Str to PHP array',
|
||||
'php_array_to_json': 'PHP array to Json',
|
||||
'url_encode_decode': 'URL encode/decode',
|
||||
},
|
||||
'SQL': {
|
||||
|
@ -40,6 +40,11 @@ const router = createRouter({
|
||||
name: 'str_to_php_array',
|
||||
component: () => import('../views/StrToPHPArray.vue'),
|
||||
},
|
||||
{
|
||||
path: '/php_array_to_json',
|
||||
name: 'php_array_to_json',
|
||||
component: () => import('../views/PHPArrayToJson.vue'),
|
||||
},
|
||||
{
|
||||
path: '/fix_ru_en_keyboard',
|
||||
name: 'fix_ru_en_keyboard',
|
||||
|
57
src/views/PHPArrayToJson.vue
Normal file
57
src/views/PHPArrayToJson.vue
Normal file
@ -0,0 +1,57 @@
|
||||
<template>
|
||||
<h2 class="tool-title">PHP array to Json</h2>
|
||||
<hr class="mt-5 mb-5">
|
||||
|
||||
<div class="input-group">
|
||||
<label for="data">Data</label>
|
||||
<textarea id="data" v-model="toolData.data" v-on:keyup="result" style="height: 150px"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<div>
|
||||
<input id="minify_json" name="minify_json" v-model="toolData.minifyJson" v-on:change="result" type="checkbox"> <label for="minify_json">minify json</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="mt-5 mb-5">
|
||||
|
||||
<div class="input-group">
|
||||
<label for="result">Result</label>
|
||||
<textarea id="result" v-model="toolResult" style="height: 150px"></textarea>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import axios from 'axios'
|
||||
import { config } from '../../config';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
toolData: {
|
||||
data: '',
|
||||
minifyJson: '',
|
||||
},
|
||||
toolResult: '',
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
result() {
|
||||
axios.post(`${config.APP_URL}/api/php/php_array_to_json.php`, {
|
||||
data: this.toolData.data,
|
||||
minify_json: this.toolData.minifyJson ? true : false,
|
||||
transformResponse: x => x
|
||||
})
|
||||
.then((response) => {
|
||||
this.toolResult = response.data.data;
|
||||
|
||||
Promise.resolve(response);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
|
||||
</style>
|
@ -4,12 +4,12 @@
|
||||
|
||||
<div class="input-group">
|
||||
<label for="data">Data</label>
|
||||
<textarea id="data" v-model="toolData.data" v-on:change="result" style="height: 150px"></textarea>
|
||||
<textarea id="data" v-model="toolData.data" v-on:keyup="result" style="height: 150px"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<label for="data_delimiter">Delimiter</label>
|
||||
<input id="data_delimiter" v-model="toolData.dataDelimiter" placeholder="," type="text" v-on:change="result" :disabled="toolData.dataIsJson">
|
||||
<input id="data_delimiter" v-model="toolData.dataDelimiter" placeholder="," type="text" v-on:keyup="result" :disabled="toolData.dataIsJson">
|
||||
|
||||
<div>
|
||||
<input id="data_is_json" name="data_is_json" v-model="toolData.dataIsJson" v-on:change="result" type="checkbox"> <label for="data_is_json">is json</label>
|
||||
@ -41,7 +41,7 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
result() {
|
||||
axios.post(`${config.APP_URL}/api/php/data_to_php_array.php`, {
|
||||
axios.post(`${config.APP_URL}/api/php/str_to_php_array.php`, {
|
||||
data: this.toolData.data,
|
||||
delimiter: this.toolData.dataDelimiter,
|
||||
mode: this.toolData.dataIsJson ? 'json' : null,
|
||||
|
Loading…
Reference in New Issue
Block a user