mysql - Remove extra backslash from only one json key value pair in php
Get the solution ↓↓↓Here is the small portion JSON generating from mysql table .
{
"id":"2",
"project_title":"Jade Heights Tower II",
"project_description":"\\u2022first one\\n\\u2022second one edited\\n",
"latitude":"10.019615",
"longitude":"76.339418",
"property_type":" Luxury Apartments",
"property_city":" Kakkanad",
"property_status":"to-sell",
"image_url":"http:\/\/zama.in\/miradmin\/assets\/images\/5d568e8ad9.jpg"
}
In this i want to remove the extra backslashes only from theproject_description
tag.
Current
"project_description":"\\u2022first one\\n\\u2022second one edited\\n"
Expected:
"project_description":"\u2022first one\n\u2022second one edited\n
"
Here is tried code.
$result = $connect->prepare("SELECT * FROM `mir_projects` ORDER BY `id`");
$result->execute();
if($result->rowCount()){
$output = $result->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($output);
}
Answer
Solution:
first, decode the json using json_decode($str,true) and then
try this,
<?php
$str="\\u2022first one\\n\\u2022second one edited\\n";
$newdescription = preg_replace('/\+/', "/\/", $str);
print_r($newdescription);
?>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: string literal contains an unescaped line break
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.