I am working on web services of Android application in PHP. I am trying to send URL with other data in JSON. But the data sent by URL shows unwanted slashes (//) in the URL.
Here is the code I am using:
if(isset($_POST['category_id'])):
$result=$db->sub_category($_POST['category_id']);
if($result):
$msg="Success";
$arr = array();
while($row=mysql_fetch_array($result)):
$arr['response'][] = array('category' => $row['category'], 'image' => "http://intelmobizsolution.com/Iphone/upload/iphone/".$row['image'], 'msg'=>$msg,'status'=>true);
endwhile;
$abc=json_encode($arr);
echo json_encode($arr);
endif;
endif;
But the result shows like this:
{"response":[{"category":"Administrative Support2","image":"http:\/\/intelmobizsolution.com\/Iphone\/upload\/iphone\/27792582102banner_02.jpg","msg":"Success","status":true}]}
How can I send a URL with JSON in the format I want?
The best approach is to accept the slashes. They do absolutely not harm. It is perfectly acceptable to have them escaped in JSON strings.
If you really want to get rid of them, then you can use:
json_encode($arr, JSON_UNESCAPED_SLASHES);
… but if your data ever includes the string </script>
and you output the JSON into some JavaScript in an HTML document, then you'll break your script.
In PHP > 5.4 you can use
json_encode($arr, JSON_UNESCAPED_SLASHES);