I am trying to fetch the content from a URL and it gives the following result. The problem is that I am unable to convert it to an array or object. I have checked other queries of similar kind and tried on them as well but I do not understand why this is not being done!
[{
"Coupon_ID": "IW12390",
"Campaign_ID": "353",
"Campaign_Name": "Dominos",
"Title": "Get 10% Off on INR 400",
"Description": "Get 10% Off on INR 400 & Above. Valid for online order only. This code is not valid on Simply Veg, Simply N-Veg Pizzas, and Combos.",
"Category": "Food & Beverages",
"Type": "Coupon",
"Type_Value": "DOM10",
"Tracking_URL": "http:\/\/tracking.icubeswire.com\/aff_c?offer_id=353&aff_id=18753",
"Added_Date": "2017-02-01",
"Expiry_Date": "2017-02-07"
},{
"Coupon_ID": "IW12392",
"Campaign_ID": "2269",
"Campaign_Name": "Shoppers Stop",
"Title": "Flat 50% on Fratini Woman",
"Description": "Flat 50% on Fratini Woman only at Shoppers Stop. So Hurry!\r\n\r\n",
"Category": "E-Commerce",
"Type": "Deal",
"Type_Value": "None",
"Tracking_URL": "http:\/\/tracking.icubeswire.com\/aff_c?offer_id=2269&aff_id=18753&url_id=16740",
"Added_Date": "2017-01-05",
"Expiry_Date": "2017-02-01"
}]
I have used following curl method to convert them to the above data and i also used file_get_contents which gives the same data as above. I tried to convert it using json_decode but the result is null.
$headers = array(
"Content-Type: application/json"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
return $result ? $result : false;