从BEHANCE.NET API中提取项目ID列表时遇到问题。
理想情况下,我想最终得到一个逗号分隔变量,如下所示:
$ids = "1,2,3,4,5"
我正在使用的当前代码:
// GET LIST OF PROJECTS AND STORE IDS IN A COMMA SEPERATED VARIABLE
$url = 'http://www.behance.net/v2/users/ami/projects?api_key=123465798';
$content = file_get_contents($url);
$json = json_decode($content, true);
$idn = count($json['project']['id']);
//echo $n;
for ($i = 0; $i < $n; $i++) {
foreach($idjson['project'] as $stat => $value) {
if (strlen(strstr($stat,'id'))) {
print $value;
}
}
}
说实话,相当困惑,任何人都知道如何在没有所有混乱的代码的情况下做到这一点(不起作用)?
以下是json Feed的副本:
感谢任何帮助!
答案 0 :(得分:1)
不完全确定你想要什么,但将其作为由逗号分隔的项目ID字符串,这是一个解决方案:
<?php
$json = <<<JSON
{"projects":[{"id":7395753,"name":"Audi A1 Custom Site","published_on":1362145162,"created_on":1362141191,"modified_on":1362145162,"url":"http://www.behance.net/gallery/Audi-A1-Custom-Site/7395753","privacy":"public","fields":["Illustration","Music"],"covers":{"115":"http://behance.vo.llnwd.net/profiles4/238348/projects/7395753/115xe6bd96dd3347f717e799ff9933f420e8.jpg","202":"http://behance.vo.llnwd.net/profiles4/238348/projects/7395753/e6bd96dd3347f717e799ff9933f420e8.jpg","230":"http://behance.vo.llnwd.net/profiles4/238348/projects/7395753/230xe6bd96dd3347f717e799ff9933f420e8.jpg","404":"http://behance.vo.llnwd.net/profiles4/238348/projects/7395753/404xe6bd96dd3347f717e799ff9933f420e8.jpg"},"mature_content":0,"mature_access":"allowed","owners":[{"id":238348,"first_name":"Am I Collective","last_name":"","username":"AMI","city":"Cape Town","state":"","country":"South Africa","company":"Am I Collective","occupation":"","created_on":1285931908,"url":"http://www.behance.net/AMI","display_name":"Am I Collective","images":{"50":"http://behance.vo.llnwd.net/profiles4/238348/50xe8d4a57490f62d866c53923a61813fbd.png","115":"http://behance.vo.llnwd.net/profiles4/238348/115xe8d4a57490f62d866c53923a61813fbd.png","138":"http://behance.vo.llnwd.net/profiles4/238348/e8d4a57490f62d866c53923a61813fbd.png"},"fields":["Illustration","Animation"]}],"stats":{"views":366,"appreciations":23,"comments":1}},{"id":7394311,"name":"Maltesers","published_on":1362139603,"created_on":1362134264,"modified_on":1362139603,"url":"http://www.behance.net/gallery/Maltesers/7394311","privacy":"public","fields":["Advertising","Illustration","Typography"],"covers":{"115":"http://behance.vo.llnwd.net/profiles4/238348/projects/7394311/115x34864465f2f050bc758bb66a5a932a11.jpg","202":"http://behance.vo.llnwd.net/profiles4/238348/projects/7394311/34864465f2f050bc758bb66a5a932a11.jpg","230":"http://behance.vo.llnwd.net/profiles4/238348/projects/7394311/230x34864465f2f050bc758bb66a5a932a11.jpg","404":"http://behance.vo.llnwd.net/profiles4/238348/projects/7394311/404x34864465f2f050bc758bb66a5a932a11.jpg"},"mature_content":0,"mature_access":"allowed","owners":[{"id":238348,"first_name":"Am I Collective","last_name":"","username":"AMI","city":"Cape Town","state":"","country":"South Africa","company":"Am I Collective","occupation":"","created_on":1285931908,"url":"http://www.behance.net/AMI","display_name":"Am I Collective","images":{"50":"http://behance.vo.llnwd.net/profiles4/238348/50xe8d4a57490f62d866c53923a61813fbd.png","115":"http://behance.vo.llnwd.net/profiles4/238348/115xe8d4a57490f62d866c53923a61813fbd.png","138":"http://behance.vo.llnwd.net/profiles4/238348/e8d4a57490f62d866c53923a61813fbd.png"},"fields":["Illustration","Animation"]}],"stats":{"views":540,"appreciations":76,"comments":10}},{"id":7393299,"name":"Tiger Beer","published_on":1362133620,"created_on":1362128831,"modified_on":1362133620,"url":"http://www.behance.net/gallery/Tiger-Beer/7393299","privacy":"public","fields":["Illustration","Packaging","Typography"],"covers":{"115":"http://behance.vo.llnwd.net/profiles4/238348/projects/7393299/115x74a9e70dd0f3a6e96efb9f854e1e0cad.jpg","202":"http://behance.vo.llnwd.net/profiles4/238348/projects/7393299/74a9e70dd0f3a6e96efb9f854e1e0cad.jpg","230":"http://behance.vo.llnwd.net/profiles4/238348/projects/7393299/230x74a9e70dd0f3a6e96efb9f854e1e0cad.jpg","404":"http://behance.vo.llnwd.net/profiles4/238348/projects/7393299/404x74a9e70dd0f3a6e96efb9f854e1e0cad.jpg"},"mature_content":0,"mature_access":"allowed","owners":[{"id":238348,"first_name":"Am I Collective","last_name":"","username":"AMI","city":"Cape Town","state":"","country":"South Africa","company":"Am I Collective","occupation":"","created_on":1285931908,"url":"http://www.behance.net/AMI","display_name":"Am I Collective","images":{"50":"http://behance.vo.llnwd.net/profiles4/238348/50xe8d4a57490f62d866c53923a61813fbd.png","115":"http://behance.vo.llnwd.net/profiles4/238348/115xe8d4a57490f62d866c53923a61813fbd.png","138":"http://behance.vo.llnwd.net/profiles4/238348/e8d4a57490f62d866c53923a61813fbd.png"},"fields":["Illustration","Animation"]}],"stats":{"views":691,"appreciations":58,"comments":9}},{"id":6838303,"name":"Mini Rocher","published_on":1359115052,"created_on":1359114176,"modified_on":1359115052,"url":"http://www.behance.net/gallery/Mini-Rocher/6838303","privacy":"public","fields":["Graphic Design","Illustration","Typography"],"covers":{"115":"http://behance.vo.llnwd.net/profiles4/238348/projects/6838303/115xe4ae17b05045ddbb8b9aaa4efb98e084.jpg","202":"http://behance.vo.llnwd.net/profiles4/238348/projects/6838303/e4ae17b05045ddbb8b9aaa4efb98e084.jpg","230":"http://behance.vo.llnwd.net/profiles4/238348/projects/6838303/230xe4ae17b05045ddbb8b9aaa4efb98e084.jpg","404":"http://behance.vo.llnwd.net/profiles4/238348/projects/6838303/404xe4ae17b05045ddbb8b9aaa4efb98e084.jpg"},"mature_content":0,"mature_access":"allowed","owners":[{"id":238348,"first_name":"Am I Collective","last_name":"","username":"AMI","city":"Cape Town","state":"","country":"South Africa","company":"Am I Collective","occupation":"","created_on":1285931908,"url":"http://www.behance.net/AMI","display_name":"Am I Collective","images":{"50":"http://behance.vo.llnwd.net/profiles4/238348/50xe8d4a57490f62d866c53923a61813fbd.png","115":"http://behance.vo.llnwd.net/profiles4/238348/115xe8d4a57490f62d866c53923a61813fbd.png","138":"http://behance.vo.llnwd.net/profiles4/238348/e8d4a57490f62d866c53923a61813fbd.png"},"fields":["Illustration","Animation"]}],"stats":{"views":2441,"appreciations":269,"comments":28}},{"id":6836557,"name":"Am I Coloring Book","published_on":1359112518,"created_on":1359101811,"modified_on":1359112518,"url":"http://www.behance.net/gallery/Am-I-Coloring-Book/6836557","privacy":"public","fields":["Character Design","Drawing","Illustration"],"covers":{"115":"http://behance.vo.llnwd.net/profiles4/238348/projects/6836557/115x1741b4321f95cb33361981cc8080cedd.jpg","202":"http://behance.vo.llnwd.net/profiles4/238348/projects/6836557/1741b4321f95cb33361981cc8080cedd.jpg","230":"http://behance.vo.llnwd.net/profiles4/238348/projects/6836557/230x1741b4321f95cb33361981cc8080cedd.jpg","404":"http://behance.vo.llnwd.net/profiles4/238348/projects/6836557/404x1741b4321f95cb33361981cc8080cedd.jpg"},"mature_content":0,"mature_access":"allowed","owners":[{"id":238348,"first_name":"Am I Collective","last_name":"","username":"AMI","city":"Cape Town","state":"","country":"South Africa","company":"Am I Collective","occupation":"","created_on":1285931908,"url":"http://www.behance.net/AMI","display_name":"Am I Collective","images":{"50":"http://behance.vo.llnwd.net/profiles4/238348/50xe8d4a57490f62d866c53923a61813fbd.png","115":"http://behance.vo.llnwd.net/profiles4/238348/115xe8d4a57490f62d866c53923a61813fbd.png","138":"http://behance.vo.llnwd.net/profiles4/238348/e8d4a57490f62d866c53923a61813fbd.png"},"fields":["Illustration","Animation"]}],"stats":{"views":844,"appreciations":47,"comments":3}},{"id":6822481,"name":"NBA Big Color","published_on":1359036303,"created_on":1359029831,"modified_on":1359037642,"url":"http://www.behance.net/gallery/NBA-Big-Color/6822481","privacy":"public","fields":["Advertising","Digital Art","Illustration"],"covers":{"115":"http://behance.vo.llnwd.net/profiles4/238348/projects/6822481/115x2f2e558313dc49ce189ef54c68739a94.jpg","202":"http://behance.vo.llnwd.net/profiles4/238348/projects/6822481/2f2e558313dc49ce189ef54c68739a94.jpg","230":"http://behance.vo.llnwd.net/profiles4/238348/projects/6822481/230x2f2e558313dc49ce189ef54c68739a94.jpg","404":"http://behance.vo.llnwd.net/profiles4/238348/projects/6822481/404x2f2e558313dc49ce189ef54c68739a94.jpg"},"mature_content":0,"mature_access":"allowed","owners":[{"id":238348,"first_name":"Am I Collective","last_name":"","username":"AMI","city":"Cape Town","state":"","country":"South Africa","company":"Am I Collective","occupation":"","created_on":1285931908,"url":"http://www.behance.net/AMI","display_name":"Am I Collective","images":{"50":"http://behance.vo.llnwd.net/profiles4/238348/50xe8d4a57490f62d866c53923a61813fbd.png","115":"http://behance.vo.llnwd.net/profiles4/238348/115xe8d4a57490f62d866c53923a61813fbd.png","138":"http://behance.vo.llnwd.net/profiles4/238348/e8d4a57490f62d866c53923a61813fbd.png"},"fields":["Illustration","Animation"]}],"stats":{"views":972,"appreciations":39,"comments":3}},{"id":6068045,"name":"What Am I?","published_on":1354109164,"created_on":1353918549,"modified_on":1354109164,"url":"http://www.behance.net/gallery/What-Am-I/6068045","privacy":"public","fields":["Crafts","Illustration","Typography"],"covers":{"115":"http://behance.vo.llnwd.net/profiles4/238348/projects/6068045/115x034135dc72041661aecfb301b2e0e48c.jpg","202":"http://behance.vo.llnwd.net/profiles4/238348/projects/6068045/034135dc72041661aecfb301b2e0e48c.jpg","230":"http://behance.vo.llnwd.net/profiles4/238348/projects/6068045/230x034135dc72041661aecfb301b2e0e48c.jpg","404":"http://behance.vo.llnwd.net/profiles4/238348/projects/6068045/404x034135dc72041661aecfb301b2e0e48c.jpg"},"mature_content":0,"mature_access":"allowed","owners":[{"id":238348,"first_name":"Am I Collective","last_name":"","username":"AMI","city":"Cape Town","state":"","country":"South Africa","company":"Am I Collective","occupation":"","created_on":1285931908,"url":"http://www.behance.net/AMI","display_name":"Am I Collective","images":{"50":"http://behance.vo.llnwd.net/profiles4/238348/50xe8d4a57490f62d866c53923a61813fbd.png","115":"http://behance.vo.llnwd.net/profiles4/238348/115xe8d4a57490f62d866c53923a61813fbd.png","138":"http://behance.vo.llnwd.net/profiles4/238348/e8d4a57490f62d866c53923a61813fbd.png"},"fields":["Illustration","Animation"]}],"stats":{"views":2049,"appreciations":211,"comments":26}},{"id":6067865,"name":"Choc Chip Yoghurt","published_on":1353916804,"created_on":1353916060,"modified_on":1353916805,"url":"http://www.behance.net/gallery/Choc-Chip-Yoghurt/6067865","privacy":"public","fields":["Character Design","Illustration","Packaging"],"covers":{"115":"http://behance.vo.llnwd.net/profiles4/238348/projects/6067865/115xc5e6f776f16150f5653662a7e2b90edc.jpg","202":"http://behance.vo.llnwd.net/profiles4/238348/projects/6067865/c5e6f776f16150f5653662a7e2b90edc.jpg","230":"http://behance.vo.llnwd.net/profiles4/238348/projects/6067865/230xc5e6f776f16150f5653662a7e2b90edc.jpg","404":"http://behance.vo.llnwd.net/profiles4/238348/projects/6067865/404xc5e6f776f16150f5653662a7e2b90edc.jpg"},"mature_content":0,"mature_access":"allowed","owners":[{"id":238348,"first_name":"Am I Collective","last_name":"","username":"AMI","city":"Cape Town","state":"","country":"South Africa","company":"Am I Collective","occupation":"","created_on":1285931908,"url":"http://www.behance.net/AMI","display_name":"Am I Collective","images":{"50":"http://behance.vo.llnwd.net/profiles4/238348/50xe8d4a57490f62d866c53923a61813fbd.png","115":"http://behance.vo.llnwd.net/profiles4/238348/115xe8d4a57490f62d866c53923a61813fbd.png","138":"http://behance.vo.llnwd.net/profiles4/238348/e8d4a57490f62d866c53923a61813fbd.png"},"fields":["Illustration","Animation"]}],"stats":{"views":1149,"appreciations":77,"comments":3}},{"id":6038735,"name":"Project Anta","published_on":1353668463,"created_on":1353667485,"modified_on":1353668464,"url":"http://www.behance.net/gallery/Project-Anta/6038735","privacy":"public","fields":["Costume Design","Illustration","Product Design"],"covers":{"115":"http://behance.vo.llnwd.net/profiles4/238348/projects/6038735/115xab2ea2108f97ee6d0305dc4cdea578a5.jpg","202":"http://behance.vo.llnwd.net/profiles4/238348/projects/6038735/ab2ea2108f97ee6d0305dc4cdea578a5.jpg","230":"http://behance.vo.llnwd.net/profiles4/238348/projects/6038735/230xab2ea2108f97ee6d0305dc4cdea578a5.jpg","404":"http://behance.vo.llnwd.net/profiles4/238348/projects/6038735/404xab2ea2108f97ee6d0305dc4cdea578a5.jpg"},"mature_content":0,"mature_access":"allowed","owners":[{"id":238348,"first_name":"Am I Collective","last_name":"","username":"AMI","city":"Cape Town","state":"","country":"South Africa","company":"Am I Collective","occupation":"","created_on":1285931908,"url":"http://www.behance.net/AMI","display_name":"Am I Collective","images":{"50":"http://behance.vo.llnwd.net/profiles4/238348/50xe8d4a57490f62d866c53923a61813fbd.png","115":"http://behance.vo.llnwd.net/profiles4/238348/115xe8d4a57490f62d866c53923a61813fbd.png","138":"http://behance.vo.llnwd.net/profiles4/238348/e8d4a57490f62d866c53923a61813fbd.png"},"fields":["Illustration","Animation"]}],"stats":{"views":1050,"appreciations":35,"comments":4}},{"id":6038511,"name":"Dusty Rebels","published_on":1353666389,"created_on":1353665693,"modified_on":1353666389,"url":"http://www.behance.net/gallery/Dusty-Rebels/6038511","privacy":"public","fields":["Character Design","Illustration","Typography"],"covers":{"115":"http://behance.vo.llnwd.net/profiles4/238348/projects/6038511/115xed8d839067b8493ad8cf553f09eedb65.jpg","202":"http://behance.vo.llnwd.net/profiles4/238348/projects/6038511/ed8d839067b8493ad8cf553f09eedb65.jpg","230":"http://behance.vo.llnwd.net/profiles4/238348/projects/6038511/230xed8d839067b8493ad8cf553f09eedb65.jpg","404":"http://behance.vo.llnwd.net/profiles4/238348/projects/6038511/404xed8d839067b8493ad8cf553f09eedb65.jpg"},"mature_content":0,"mature_access":"allowed","owners":[{"id":238348,"first_name":"Am I Collective","last_name":"","username":"AMI","city":"Cape Town","state":"","country":"South Africa","company":"Am I Collective","occupation":"","created_on":1285931908,"url":"http://www.behance.net/AMI","display_name":"Am I Collective","images":{"50":"http://behance.vo.llnwd.net/profiles4/238348/50xe8d4a57490f62d866c53923a61813fbd.png","115":"http://behance.vo.llnwd.net/profiles4/238348/115xe8d4a57490f62d866c53923a61813fbd.png","138":"http://behance.vo.llnwd.net/profiles4/238348/e8d4a57490f62d866c53923a61813fbd.png"},"fields":["Illustration","Animation"]}],"stats":{"views":1092,"appreciations":61,"comments":9}},{"id":6038075,"name":"Converse","published_on":1353663548,"created_on":1353661962,"modified_on":1353663548,"url":"http://www.behance.net/gallery/Converse/6038075","privacy":"public","fields":["Illustration","Street Art","Typography"],"covers":{"115":"http://behance.vo.llnwd.net/profiles4/238348/projects/6038075/115x1f81170cdb985847a23b9e066ce06f8b.jpg","202":"http://behance.vo.llnwd.net/profiles4/238348/projects/6038075/1f81170cdb985847a23b9e066ce06f8b.jpg","230":"http://behance.vo.llnwd.net/profiles4/238348/projects/6038075/230x1f81170cdb985847a23b9e066ce06f8b.jpg","404":"http://behance.vo.llnwd.net/profiles4/238348/projects/6038075/404x1f81170cdb985847a23b9e066ce06f8b.jpg"},"mature_content":0,"mature_access":"allowed","owners":[{"id":238348,"first_name":"Am I Collective","last_name":"","username":"AMI","city":"Cape Town","state":"","country":"South Africa","company":"Am I Collective","occupation":"","created_on":1285931908,"url":"http://www.behance.net/AMI","display_name":"Am I Collective","images":{"50":"http://behance.vo.llnwd.net/profiles4/238348/50xe8d4a57490f62d866c53923a61813fbd.png","115":"http://behance.vo.llnwd.net/profiles4/238348/115xe8d4a57490f62d866c53923a61813fbd.png","138":"http://behance.vo.llnwd.net/profiles4/238348/e8d4a57490f62d866c53923a61813fbd.png"},"fields":["Illustration","Animation"]}],"stats":{"views":1293,"appreciations":58,"comments":5}},{"id":6037717,"name":"Bells Whiskey Installation","published_on":1353660322,"created_on":1353658771,"modified_on":1353660465,"url":"http://www.behance.net/gallery/Bells-Whiskey-Installation/6037717","privacy":"public","fields":["Branding","Illustration","Typography"],"covers":{"115":"http://behance.vo.llnwd.net/profiles4/238348/projects/6037717/115x00828589e0ca019720d9ee529b217778.jpg","202":"http://behance.vo.llnwd.net/profiles4/238348/projects/6037717/00828589e0ca019720d9ee529b217778.jpg","230":"http://behance.vo.llnwd.net/profiles4/238348/projects/6037717/230x00828589e0ca019720d9ee529b217778.jpg","404":"http://behance.vo.llnwd.net/profiles4/238348/projects/6037717/404x00828589e0ca019720d9ee529b217778.jpg"},"mature_content":0,"mature_access":"allowed","owners":[{"id":238348,"first_name":"Am I Collective","last_name":"","username":"AMI","city":"Cape Town","state":"","country":"South Africa","company":"Am I Collective","occupation":"","created_on":1285931908,"url":"http://www.behance.net/AMI","display_name":"Am I Collective","images":{"50":"http://behance.vo.llnwd.net/profiles4/238348/50xe8d4a57490f62d866c53923a61813fbd.png","115":"http://behance.vo.llnwd.net/profiles4/238348/115xe8d4a57490f62d866c53923a61813fbd.png","138":"http://behance.vo.llnwd.net/profiles4/238348/e8d4a57490f62d866c53923a61813fbd.png"},"fields":["Illustration","Animation"]}],"stats":{"views":1112,"appreciations":75,"comments":9}}],"http_code":200}
JSON;
$data = json_decode($json, true);
$ids = array();
foreach ($data['projects'] as $project) {
$ids[] = $project['id'];
}
echo implode(',', $ids);
7395753,7394311,7393299,6838303,6836557,6822481,6068045,6067865,6038735,6038511,6038075,6037717