how to remove slashes from my json result with cakePHP
I've built a REST webservice and I want to remove the slashes from my json result. I have some data stored in my DB, which one of the fields contains a websitelink开发者_运维知识库s.I can access them through my normal-view which is html and through my json-view. The normal returns de links normal but the json ads slashes to it like:
http:\/\/mywebsite\/company\/upload\/siteman\/thumbnails\/carr\/
How can i remove this? Here is my cakephp code:
// De html view
<h2>View all posts</h2>
<table>
<tr>
<th>Title</th>
<th>Body</th>
</tr>
<?php foreach($images as $image):?>
<tr>
<td><?php echo $image['Image']['id'];?></td>
<td><?php echo $image['Image']['plaatjes'];?></td>
</tr>
<?php endforeach; ?>
</table>
// The json view
<?php
echo json_encode($images);
?>
Use str_replace
, like this:
<?php
echo str_replace('\/','/',json_encode($images));
?>
You can also try JSON_UNESCAPED_SLASHES
, like this:
<?php
echo json_encode($images,JSON_UNESCAPED_SLASHES);
?>
精彩评论