Reputation: 1665
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 the project_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);
}
Upvotes: 2
Views: 229
Reputation: 772
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);
?>
Upvotes: 2