Home » Php » php – How to deal with backslashes (because of parenthesis) in json using laravel?

php – How to deal with backslashes (because of parenthesis) in json using laravel?

Posted by: admin February 25, 2020 Leave a comment

Questions:

I have text

This is Laravel's package. Following terms and conditions ("Terms")

Above text I want to return as json through laravel api, the problem is I am getting string with backslashes because of parenthesis.

I am trying following

$content = 'This is Laravel\'s package. Following terms and conditions ("Terms")';
$data =  str_replace(PHP_EOL, '', $content);
echo response()->json([ 'data' => $data ]);

Which output is following

{"data":"This is Laravel's package. Following terms and conditions (\"Terms\")"}
How to&Answers: