This question already has an answer here:
How to extract and access data from JSON with PHP?
(1 answer)
Closed 4 years ago.
Ok... so the following works so far:
// Open connection
$ch = curl_init();
// Make the curl call
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$head = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$data = json_decode($head, true);
foreach($data['events'] as $key => $item) {
// $event_id = $data['events'][$key]['eventId'];
$event_id = $item['eventId'];
// $name = $data['events'][$key]['name'];
$name = $item['name'];
// $desc = $data['events'][$key]['description'];
$desc = $item['description'];
echo "ID: $event_id<br>
NAME: $name<br>
DESCRIPTION: $desc<br>
<br>";
}
However, I am trying multiple things and I am unable to capture "primaryImage" and "categories" data out of the arrays in the same JSON output and I am having difficulties with the syntax. Here is an example of the data:
{
"eventId": 5183191,
"name": "The Rhythm Rockets - FREE",
"description": "Summer Concert Series - The Rhythm Rockets . .\nFREE. Look for a YELLOW balloon. Bring a chair. PLEASE BE ON TIME (6:00 PM!) TO SIT WITH THE GROUP. Allow time for street parking. Expect a crowd. Meetup at 6pm - Showtime is 7pm. Food, wine and beer will be on sale.\nIn case of inclement weather, concerts will be held indoors at the Lincoln Center, 935 Maple Avenue. For weather updates, call[masked] after 5:30 pm. If moved inside, there is no way we can sit together.",
"primaryImage": {
"smallImageUrl": "https://domainnamestorage.blob.core.windows.net/portalimages/portalimages/71021444-d72d-456c-a419-36b61ead5259.small.png",
"mediumImageUrl": "https://domainnamestorage.blob.core.windows.net/portalimages/portalimages/71021444-d72d-456c-a419-36b61ead5259.medium.png",
"largeImageUrl": "https://domainnamestorage.blob.core.windows.net/portalimages/portalimages/71021444-d72d-456c-a419-36b61ead5259.large.png"
},
"categories": [{
"categoryId": 2,
"parentCategoryId": null,
"name": "Performing Arts"
}, {
"categoryId": 12,
"parentCategoryId": null,
"name": "Food & Drink"
}, {
"categoryId": 17,
"parentCategoryId": 2,
"name": "Music"
}, {
"categoryId": 75,
"parentCategoryId": 12,
"name": "Drinks"
}, {
"categoryId": 100,
"parentCategoryId": 17,
"name": "Concerts"
}],
"location": {
"latitude": 41.792683,
"longitude": -88.011765,
"city": "Downers Grove",
"state": "IL",
"address": "1000 Grove St",
"country": "United States",
"locationName": "Fishel Park"
},
"instances": [{
"startDateTime": "2018-08-21T18:00:00Z",
"endDateTime": null,
"hasTime": true,
"allDay": false
}],
"price": {
"lowerPrice": null,
"upperPrice": null,
"free": false,
"description": null
},
"lastUpdatedDate": "2018-07-26T02:20:49.686Z",
"popularity": null,
"interest": 50,
"links": [{
"isSponsor": false,
"name": "Meetup",
"linkUrl": "https://www.meetup.com/Im-Not-Dead-Yet-50-plus/events/252406255/",
"logoUrl": null
}, {
"isSponsor": true,
"name": "I'm Not Dead Yet --- 50+ Meetup",
"linkUrl": "http://Meetup.com/Im-Not-Dead-Yet-50-plus",
"logoUrl": null
}, {
"isSponsor": true,
"name": "I'm Not Dead Yet --- 50+ Meetup",
"linkUrl": "http://Meetup.com/Im-Not-Dead-Yet-50-plus",
"logoUrl": null
}],
"previousEventIds": [],
"seriesStart": "2018-08-21T18:00:00Z",
"seriesEnd": null,
"url": "http://portal.domainname.com/m/FireVite#!/details/THE-RHYTHM-ROCKETS-FREE/5183191/2018-08-21T18",
"handPicked": false,
"customField": null,
"contact": {
"organization": null,
"name": null,
"email": null,
"phone": null
},
"media": null
}
I would like to use data as PHP string variables that are found within elements such as "primaryImage", "categories", "location", etc.
Should be like this:
echo $item['primaryImage']->smallImageUrl;
Related
Here is the code using which i am getting data:
<?php
header('Content-Type: text/html; charset=UTF-8');
$request = file_get_contents('php://input');
//$req_dump = print_r( $request, true );
$fp = file_put_contents( 'request.log', urldecode(json_encode($request)));
?>
output :
domain_prefix = test & payload = {
"attributed_cost": "0.00",
"count": 50,
"id": "da674e25-5d9c-a8e2-1d5e-aa018b6cc1c3",
"outlet": {
"id": "3faf0608-91fa-11e3-a0f5-b8ca3a64f8f4",
"name": "West End Shop",
"tax_id": "e52b2846-e920-11e5-f98b-29c175501027",
"time_zone": "Australia/Brisbane"
},
"outlet_id": "3faf0608-91fa-11e3-a0f5-b8ca3a64f8f4",
"product": {
"active": true,
"attributed_cost": null,
"base_name": "Test Productss",
"button_order": null,
"categories": [],
"deleted_at": null,
"description": "",
"handle": "testproducts",
"id": "bfe919c4-6357-46c9-a333-d1db636446c5",
"name": "Test Productss",
"sku": "10203",
"source": "USER",
"source_id": null,
"source_variant_id": null,
"supply_price": "0.00",
"taxes": [{
"outlet_id": "3faf0608-91fa-11e3-a0f5-b8ca3a64f8f4",
"tax_id": "e52b2846-e920-11e5-f98b-29c175501027"
}],
"variant_options": [],
"variant_parent_id": null
},
"product_id": "bfe919c4-6357-46c9-a333-d1db636446c5",
"reorder_point": "0",
"restock_level": "0",
"version": 16073287694
} & retailer_id = 3 fa8309c - 91 fa - 11e3 - a0f5 - b8ca3a64f8f4 & type = inventory.update
I am not sure how to fetch "count" & "id" & "product_id" attributes value from this.
I have tried parse_str but it didn't work.
let me know your thoughts on this, how to fetch data from it ?
Thankyou
if your $request is like that output then you can try
you can try
parse_str($request, $parse_request);
$payload = json_decode($parse_request["payload"], true);
$id = $payload["id"];
$count = $payload["count"];
$product_id = $payload["product"]["id"];
I'm very new to the world of APIs and am currently trying to display all reviews I have on my reviews.io account for a specific product. I've tried to make the following script, which now seems to work, however, I would love to have the results sorted nicely in a for-each loop.
Here my current script:
<?php
$header_data = array(
'store' => 'MYSHOP',
'apikey' => 'MYKEY',
'method' => 'GET'
);
$ch = curl_init();
$curlOpts = array(
CURLOPT_URL => 'https://api.reviews.co.uk/product/review?store=MYSHOP&sku=TSCB20&apikey=MYKEY',
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HEADER => false
);
curl_setopt_array($ch, $curlOpts);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Length: 0'));
$rv = curl_exec($ch);
$data = json_decode($rv,true);
curl_close($ch);
?>
This outputs all reviews in Raw code or JSON I believe, however, I would like to have them displayed nicely in a div for each item.
The output is as follows (formatted):
{
"store": {
"name": "",
"logo": ""
},
"stats": {
"average": "5.0000",
"count": 2
},
"reviews": {
"total": 2,
"per_page": 15,
"current_page": 1,
"last_page": 1,
"from": 1,
"to": 2,
"data": [
{
"votes": null,
"flags": null,
"title": "David",
"product_review_id": 2978412,
"review": "...is beautiful and I had a great time on this tour. Already started to plan my next trip with them",
"sku": "TSCB20",
"rating": 5,
"date_created": "",
"order_id": "",
"timeago": "",
"reviewer": {
"first_name": "David",
"last_name": "",
"verified_buyer": "yes",
"address": "",
"profile_picture": "",
"gravatar": "38677a4e8a55189055d6e5bf2efa9ade"
},
"ratings": [],
"replies": [],
"images": [],
"product": {
"sku": "TSCB20",
"name": "",
"description": "",
"link": "",
"image_url": "",
"mpn": "",
"brand": null,
"category": null,
"custom": null
},
"author": {
"email": "david#"
}
},
{
"votes": null,
"flags": null,
"title": null,
"product_review_id": 2978009,
"review": "Exceeded expectations on all fronts cultural and Food ",
"sku": "TSCB20",
"rating": 5,
"date_created": "",
"order_id": "RGFY4ZG",
"timeago": "",
"reviewer": {
"first_name": "Alan",
"last_name": "",
"verified_buyer": "yes",
"address": "",
"profile_picture": "",
"gravatar": "64e2ac644a158b76a82f9e1c5c2886f5"
},
"ratings": [],
"replies": [],
"images": [],
"product": {
"sku": "TSCB20",
"name": "",
"description": "",
"link": "",
"image_url": "",
"mpn": "",
"brand": null,
"category": null,
"custom": null
},
"author": {
"email": ""
}
}
]
},
"ratings": [],
"settings": {
"write_review_button": 1,
"disable_product_seo_css": 0,
"show_product_review_titles": 0
},
"word": "Excellent",
"products": [
{
"sku": "TSCB20",
"name": ""
}
],
"write_review_link": ""
}
My ideal outcome now would be a loop, that fetches the reviewer's name, the review itself and the star-rating. e.g.
<p class="review">Review here</p>
<p class="reviewer">Name here</p>
<p class="rating">Rating here</p>
So technically based on the current output, I should have 2 reviews. Some expert help would be greatly appreciated as I am very new to APIs. Thank you very much in advance.
Simple foreach() will do the job:
<?php foreach($data['reviews']['data'] as $dat){?>
<p class="review"><?php echo $dat['review'];?></p>
<p class="reviewer"><?php echo trim($dat['reviewer']['first_name'].' '.$dat['reviewer']['last_name']);?></p>
<p class="rating"><?php echo $dat['rating'];?></p>
<?php }?>
This question already has an answer here:
How to extract and access data from JSON with PHP?
(1 answer)
Closed 4 years ago.
I'm new into PHP and JSON and I have a problem, I want to retrieve a item and value from a JSON:
{
"status": true,
"webhook_type": 100,
"data": {
"product": {
"id": "lSEADIQ",
"attachment_id": null,
"title": "Registration",
"description": null,
"image": null,
"unlisted": false,
"type": "service",
"price": 1,
"currency": "EUR",
"email": {
"enabled": false
},
"stock_warning": 0,
"quantity": {
"min": 1,
"max": 1
},
"confirmations": 1,
"custom_fields": [
{
"name": "Forum username",
"type": "text",
"required": true
}
],
"gateways": [
"Bitcoin"
],
"webhook_urls": [],
"dynamic_url": "",
"position": null,
"created_at": "2018-10-01 12:51:12",
"updated_at": "2018-10-01 12:55:46",
"stock": 9223372036854776000,
"accounts": []
},
"order": {
"id": "8e23b496-121a-4dc6-8ec4-c45835680db2",
"created_at": "Tue, 02 Oct 2018 00:54:56 +0200",
"paid_at": null,
"transaction_id": null,
"confirmations": 1,
"required_confirmations": 3,
"received_amount": 0,
"crypto_address": "1NeNQws7JLbTr6bjekfeaXSV7XiyRsv7V8",
"crypto_amount": "0.4815",
"quantity": 1,
"price": 19.99,
"currency": "EUR",
"exchange_rate": "1.21",
"gateway": "BTC",
"email": "webhook#site.gg",
"ip_address": "123.456.789.111",
"agent": {
"geo": {
"ip": "214.44.18.6",
"iso_code": "US",
"country": "United States"
},
"data": {
"is_mobile": false,
"is_table": false,
"is_desktop": true,
"browser": {
"name": "Chrome",
"version": "63.0.3239.132"
}
}
},
"custom_fields": [
{
"name": "user_id",
"value": 184191
}
],
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3)"
}
}
}
I want to retrieve items from data -> order, for example "id" or "ip_address".
Thank you for read this, I hope someone can help me in this, because I'm lost, I started to code very recently and I'm trying to learn a lot.
Regards!
Where test.json is the json you uploaded, place it in a file named test.json and ensure its placed in the same directory.
<?php
$load = file_get_contents("test.json") or die("JSON load failed");
$json_a = json_decode($load, true);
print $json_a['data']['order']['ip_address'] . "\n";
?>
Gives:
123.456.789.111
My answer reads the JSON from a file as were it dumped directly in your code, which indeed it could be, it would make the code less readable and your file more messy.
If you dont want to place the file in the same directory, simply specify the full file path. E.g. file_get_contents("this/dir/here/test.json");
You can read about how json_decode works here, its essential we pass it the true parameter to make our arrays associative.
You can extract your need array from JSON data. You can use a loop too to read all your data inside the order array.
$array = json_decode($json, true);
$verbose = $array['data'];
$orderArray = $verbose['order'];
print_r($orderArray);
echo $orderArray['id'];
echo $orderArray['ip_address'];
I am accessing API for "ConnectWise". the data comes into JSON format. i was able to parse the data into table via PHP. however, empty fields in JSON results in Undefined index. This happens for some items with no website, or address for example. the rest shows up fine.
Any help or input would be appreciated.
Here is my code to get the data from Connectwise:
function get_companies(){
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($curl, CURLOPT_URL, "https://api-
na.myconnectwise.net/v4_6_release/apis/3.0/company/companies");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
"Authorization: Basic (OUR KEY)",
'Content-type: application/json'
));
$result = curl_exec($curl);
curl_close($curl);
$decoded = json_decode($result,true);
return $decoded;
}
And to display the data:
function list_all_accounts(){
$accounts = get_companies();
if ( !empty ($accounts)){
foreach ($accounts as $account) {
{
echo "
</td>
<td>
$account[id]
</td>
<td>
$account[name]
</td>
<td>
$account[addressLine1]
</td>
<td>
$account[phoneNumber]
</td>
<td>
$account[website]
</td>
<td>
$account[name]
</td>
</tr>";
}
}
}
}
Update - Json Sample
[
{
"id": 250,
"identifier": "company name ",
"name": "company name",
"status": {
"id": 1,
"name": "Active",
"_info": {
"status_href": "https://api-na.myconnectwise.net/v4_6_release/apis/3.0/company/companies/statuses/1"
}
},
"type": {
"id": 1,
"name": "Client",
"_info": {
"type_href": "https://api-na.myconnectwise.net/v4_6_release/apis/3.0/company/companies/types/1"
}
},
"addressLine1": "address line 1",
"city": "New York",
"state": "NY",
"zip": "11111",
"country": {
"id": 1,
"name": "United States",
"_info": {
"country_href": "https://api-na.myconnectwise.net/v4_6_release/apis/3.0/company/countries/1"
}
},
"phoneNumber": "123456789",
"faxNumber": "",
"website": "www.site.com",
"territoryId": 2,
"accountNumber": "",
"dateAcquired": "2006-06-21T04:00:00Z",
"sicCode": {
"id": 1209,
"name": "consulting"
},
"annualRevenue": 0,
"timeZone": {
"id": 1,
"name": "GMT-5/Eastern Time: US & Canada",
"_info": {
"timeZoneSetup_href": "https://api-na.myconnectwise.net/v4_6_release/apis/3.0/system/timeZoneSetups/1"
}
},
"leadFlag": false,
"unsubscribeFlag": false,
"userDefinedField5": "1",
"taxCode": {
"id": 8,
"name": "Tax-State",
"_info": {
"taxCode_href": "https://api-na.myconnectwise.net/v4_6_release/apis/3.0/finance/taxCodes/8"
}
},
"billingTerms": {
"id": 1,
"name": "Net 30 days"
},
"billToCompany": {
"id": 250,
"identifier": "comp1 ",
"name": "company1.",
"_info": {
"company_href": "https://api-na.myconnectwise.net/v4_6_release/apis/3.0/company/companies/250"
}
},
"billingSite": {
"id": 1291,
"name": "company1",
"_info": {
"site_href": "https://api-na.myconnectwise.net/v4_6_release/apis/3.0/company/companies"
}
},
"invoiceDeliveryMethod": {
"id": 1,
"name": "Mail"
},
"deletedFlag": false,
"mobileGuid": "1df91371-6d7a-4778-ab81-f3e7761f5211",
"currency": {
"id": 7,
"symbol": "$",
"isoCode": "USD",
"name": "US Dollars",
"_info": {
"currency_href": "https://api-na.myconnectwise.net/v4_6_release/apis/3.0/finance/currencies/7"
}
},
"_info": {
"lastUpdated": "2018-04-02T16:36:05Z",
"updatedBy": "user1",
"dateEntered": "2006-06-21T16:04:59Z",
}
},
{
"id": 250,
"identifier": "company name ",
"name": "company name",
"status": {
"id": 1,
"name": "Active",
"_info": {
"status_href": "https://api-na.myconnectwise.net/v4_6_release/apis/3.0/company/companies/statuses/1"
}
},
"type": {
"id": 1,
"name": "Client",
"_info": {
"type_href": "https://api-na.myconnectwise.net/v4_6_release/apis/3.0/company/companies/types/1"
}
},
"addressLine1": "address line 1",
"city": "New York",
"state": "NY",
"zip": "11111",
"country": {
"id": 1,
"name": "United States",
"_info": {
"country_href": "https://api-na.myconnectwise.net/v4_6_release/apis/3.0/company/countries/1"
}
},
"phoneNumber": "123456789",
"faxNumber": "",
"website": "www.site.com",
"territoryId": 2,
"accountNumber": "",
"dateAcquired": "2006-06-21T04:00:00Z",
"sicCode": {
"id": 1209,
"name": "consulting"
},
"annualRevenue": 0,
"timeZone": {
"id": 1,
"name": "GMT-5/Eastern Time: US & Canada",
"_info": {
"timeZoneSetup_href": "https://api-na.myconnectwise.net/v4_6_release/apis/3.0/system/timeZoneSetups/1"
}
},
"leadFlag": false,
"unsubscribeFlag": false,
"userDefinedField5": "1",
"taxCode": {
"id": 8,
"name": "Tax-State",
"_info": {
"taxCode_href": "https://api-na.myconnectwise.net/v4_6_release/apis/3.0/finance/taxCodes/8"
}
},
"billingTerms": {
"id": 1,
"name": "Net 30 days"
},
"billToCompany": {
"id": 250,
"identifier": "comp1 ",
"name": "company1.",
"_info": {
"company_href": "https://api-na.myconnectwise.net/v4_6_release/apis/3.0/company/companies/250"
}
},
"billingSite": {
"id": 1291,
"name": "company1",
"_info": {
"site_href": "https://api-na.myconnectwise.net/v4_6_release/apis/3.0/company/companies"
}
},
"invoiceDeliveryMethod": {
"id": 1,
"name": "Mail"
},
"deletedFlag": false,
"mobileGuid": "1df91dd371-6d7addd-4778s-ab81-f3e7761f5211",
"currency": {
"id": 7,
"symbol": "$",
"isoCode": "USD",
"name": "US Dollars",
"_info": {
"currency_href": "https://api-na.myconnectwise.net/v4_6_release/apis/3.0/finance/currencies/7"
}
},
"_info": {
"lastUpdated": "2018-04-02T16:36:05Z",
"updatedBy": "user1",
"dateEntered": "2006-06-21T16:04:59Z",
"enteredBy": "CONVERSION",
}
}
]
json_decode() and https://jsonlint.com/ both complain about the comma after the value on lines 95 and 194. Removing them makes it valid json, after which your code works as soon as you remember to quote the key values for the associative array.
I removed the two offending commas in the json and saved as a file, then added the quoting for your key values on the array, and finally removed the HTML table stuff and such (I'm just running it on command line to see output). Should be easy to put back in...
<?php
function get_companies() {
$j = file_get_contents("json.json");
$jd = json_decode($j, true);
return $jd;
}
$accounts = get_companies();
if (!empty($accounts)) {
foreach ($accounts as $account) {
echo "\n".$account['id'] . "
" . $account['name'] . "
" . $account['addressLine1'] . "
" . $account['phoneNumber'] . "
" . $account['website'] . "
" . $account['name']."\n\n";
}
}
?>
According to your comment, it is possible that some properties that you use in your HTML are not part of the JSON you receive. This means you are accessing an array index that is not set, e.g. with $account[website].
I see two solutions for this:
Only output the data if it is set in the array:
echo '<td>'.(isset($account['website']) ? $account['website'] : '').'</td>';
Use a an array with defaults for all the values as base for your $account array and merge them:
$base = [
'website' => 'no website',
'phoneNumber' => '',
];
foreach ($accounts as $account) {
// this will override all elements of $base with them of $account,
// but only if they are present in $account
$account = array_merge($base, $account);
// ... your output here ...
}
I'm currently using the NYT News API to search for articles. I'm trying to get the Article Name, and URL from the JSON. How do I do this for each entry in the JSON?
$curl = curl_init();
$call = 'http://api.nytimes.com/svc/search/v2/articlesearch.json? q=Denmark&begin_date=20040112&end_date=20041212&sort=oldest&api-key=mykey';
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $call,
CURLOPT_USERAGENT => 'Codular Sample cURL Request'
));
// Send the request & save response to $resp
echo $resp = curl_exec($curl);
curl_close($curl);
//Decode Json
$y = json_decode($resp,true);
It returns a large JSON, I'm interested in retrieving the weburl, and headline field. I've tried:
$url = $y['response']['docs']['web_url']
and
$headline = $y['response']['docs']['headline']
but with no success. Any thoughts?
I also need all the entries that have a web_url and headline in the JSON.
A single article entry from the JSON response:
{
"response": {
"meta": {
"hits": 291,
"time": 102,
"offset": 0
},
"docs": [{
"web_url": "http://www.nytimes.com/2005/01/14/arts/design/14anti.html",
"snippet": "On Wednesday, Christie's New York is having what it claims is the first-ever auction devoted solely to Georg Jensen silver, with some 800 objects.",
"lead_paragraph": "Georg Jensen silver from Denmark has a tactile quality all its own, probably because it is handmade. It gets only better with age. Michael von Essen, the founder and curator of the Georg Jensen Museum in Copenhagen, tried to explain its appeal: ''Once you have touched pieces of Jensen, you want to have them. The silver has a warmth to it, whether the style is 1900, Art Deco or modern.'' Last year, the company Georg Jensen founded celebrated its 100th anniversary. Jensen, who was not a gifted businessman, would probably have been surprised.",
"abstract": "Wendy Moonan Antiques column profiles Danish silversmith Georg Jensen, whose company celebrated its centennial last year; Michael von Essen, founder and curator of Georg Jensen Museum in Copenhagen, is giving talk about Jensen at Christie's, comments; photo (M)",
"print_page": "41",
"blog": [],
"source": "The New York Times",
"multimedia": [],
"headline": {
"main": "From Denmark, Moonlight's Glow",
"kicker": "Antiques"
},
"keywords": [{
"name": "persons",
"value": "JENSEN, GEORG"
}, {
"name": "persons",
"value": "VON ESSEN, MICHAEL"
}, {
"name": "organizations",
"value": "CHRISTIE'S"
}, {
"name": "subject",
"value": "JEWELS AND JEWELRY"
}, {
"name": "subject",
"value": "ANTIQUES"
}, {
"name": "subject",
"value": "AUCTIONS"
}, {
"name": "subject",
"value": "ART"
}, {
"name": "subject",
"value": "SILVER"
}],
"pub_date": "2005-01-14T00:00:00Z",
"document_type": "article",
"news_desk": "Leisure/Weekend Desk",
"section_name": "Arts",
"subsection_name": null,
"byline": {
"person": [{
"organization": "",
"role": "reported",
"rank": 1,
"firstname": "Wendy",
"lastname": "Moonan"
}],
"original": "By Wendy Moonan"
},
"type_of_material": "News",
"_id": "4fd2a5708eb7c8105d88d3af",
"word_count": 1152,
"slideshow_credits": null
}]
},
"status": "OK",
"copyright": "Copyright (c) 2013 The New York Times Company. All Rights Reserved."
}
The Json Weburl data in the JSON can be accessed using the line: $y['response']['docs'][0]['web_url']
The 0 can be replaced with an index variable such as i to retrieve multiple web_url entries, and placed in a for loop.
for(i=0;i<3;i++)
{
$y['response']['docs'][i]['web_url']
}