I need to escape json encoded string.
I have encode below string.
json_encode(['test1' => '','test2' => '','test3' => ''])
It will store in mysql table like,
"{\"test1\":\"\",\"test2\":\"\",\"test3\":\"\"}"
I want to store like,
{"test":"","test2":"","test3":""}
Thank you !
Try below code
<?php
$json = json_encode(['test1' => '','test2' => '','test3' => '']);
$dbjson = "{\"title\":\"\",\"description\":\"\",\"keywords\":\"\"}";
echo "<pre>";
$value = json_encode(json_decode($dbjson));
print_r($value); // output : {"title":"","description":"","keywords":""}
?>
Add JSON_UNESCAPED_SLASHES as last argument
echo json_encode(['test1' => '','test2' => '','test3' => ''],JSON_UNESCAPED_SLASHES)
Output
{"test1":"","test2":"","test3":""}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With