iplaylol Posted April 5, 2014 Share Posted April 5, 2014 input <?php $ch = curl_init(); // initiate curl $urlname = "https://prod.api.pvp.net/api/lol/na/v1.4/summoner/by-name/$username?api_key=XXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // where you want to post data curl_setopt($ch, CURLOPT_URL,$urlname); $output = curl_exec ($ch); output {"ryze":{"id":329,"name":"Ryze","profileIconId":575,"summonerLevel":30,"revisionDate":1396705964000}} Question How would I be able to isolate and record only the "id" or "profileIconId" for example? Quote Link to comment https://forums.phpfreaks.com/topic/287548-curl-function/ Share on other sites More sharing options...
trq Posted April 5, 2014 Share Posted April 5, 2014 json_decode Quote Link to comment https://forums.phpfreaks.com/topic/287548-curl-function/#findComment-1475074 Share on other sites More sharing options...
iplaylol Posted April 5, 2014 Author Share Posted April 5, 2014 I have already looked at that and have tried many examples with no luck. do I have to use foreach or array? Quote Link to comment https://forums.phpfreaks.com/topic/287548-curl-function/#findComment-1475086 Share on other sites More sharing options...
Rifts Posted April 5, 2014 Share Posted April 5, 2014 json_decode Quote Link to comment https://forums.phpfreaks.com/topic/287548-curl-function/#findComment-1475087 Share on other sites More sharing options...
trq Posted April 6, 2014 Share Posted April 6, 2014 I have already looked at that and have tried many examples with no luck. Post your problematic code then. Quote Link to comment https://forums.phpfreaks.com/topic/287548-curl-function/#findComment-1475094 Share on other sites More sharing options...
iplaylol Posted April 6, 2014 Author Share Posted April 6, 2014 So i changed some things Input $urlname = "https://prod.api.pvp.net/api/lol/na/v1.4/summoner/by-name/$username?api_key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";$ch = curl_init($urlname); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);$output = curl_exec ($ch);$names = json_decode($output,true); foreach($arr as $val) { echo $val['id']; }print_r($names);curl_close($ch); Output Array ( [ryze] => Array ( [id] => 329 [name] => Ryze [profileIconId] => 575 [summonerLevel] => 30 [revisionDate] => 1396735149000 ) ) Desired output 329 --------------------------- From my research i understand i must do something with foreach and arrays but all my attempts have yielded blank resutls. Quote Link to comment https://forums.phpfreaks.com/topic/287548-curl-function/#findComment-1475169 Share on other sites More sharing options...
trq Posted April 7, 2014 Share Posted April 7, 2014 <?php echo $names['ryze']['id']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/287548-curl-function/#findComment-1475181 Share on other sites More sharing options...
iplaylol Posted April 7, 2014 Author Share Posted April 7, 2014 (edited) One more quick question, how would i be able to print out a resut if keys are involved? Example: This is what i came up with : echo $recentd[$id]['1337783965'][1]['mapId']; Array ( [summonerId] => 32339969 [games] => Array ( [0] => Array ( [gameId] => 1337783965 [invalid] => [gameMode] => CLASSIC [gameType] => MATCHED_GAME [subType] => RANKED_SOLO_5x5 [mapId] => 1 [teamId] => 100 [championId] => 121 [spell1] => 4 [spell2] => 14 [level] => 30 [ipEarned] => 226 [createDate] => 1396843055315 [fellowPlayers] => Array ( [0] => Array ( [summonerId] => 22979188 [teamId] => 100 [championId] => 236 ) [1] => Array ( [summonerId] => 37171718 [teamId] => 100 [championId] => 89 ) [2] => Array ( [summonerId] => 21674100 [teamId] => 200 [championId] => 30 ) [3] => Array ( [summonerId] => 20392723 [teamId] => 200 [championId] => 19 ) [4] => Array ( [summonerId] => 24461726 [teamId] => 200 [championId] => 62 ) [5] => Array ( [summonerId] => 493753 [teamId] => 100 [championId] => 4 ) [6] => Array ( [summonerId] => 32612086 [teamId] => 200 [championId] => 53 ) [7] => Array ( [summonerId] => 19031131 [teamId] => 100 [championId] => 60 ) [8] => Array ( [summonerId] => 23059379 [teamId] => 200 [championId] => 222 ) ) [stats] => Array ( [level] => 13 [goldEarned] => 9085 [numDeaths] => 1 [turretsKilled] => 2 [minionsKilled] => 149 [championsKilled] => 5 [goldSpent] => 7270 [totalDamageDealt] => 81120 [totalDamageTaken] => 12729 [doubleKills] => 1 [killingSprees] => 1 [largestKillingSpree] => 4 [team] => 100 [win] => 1 [neutralMinionsKilled] => 6 [largestMultiKill] => 2 [physicalDamageDealtPlayer] => 79322 [magicDamageDealtPlayer] => 1130 [physicalDamageTaken] => 7506 [magicDamageTaken] => 4873 [timePlayed] => 1369 [totalHeal] => 1977 [totalUnitsHealed] => 1 [assists] => 5 [item0] => 2044 [item1] => 3074 [item3] => 3111 [item4] => 3035 [item6] => 3340 [sightWardsBought] => 3 [magicDamageDealtToChampions] => 1006 [physicalDamageDealtToChampions] => 11602 [totalDamageDealtToChampions] => 12956 [trueDamageDealtPlayer] => 668 [trueDamageDealtToChampions] => 348 [trueDamageTaken] => 349 [wardPlaced] => 3 [neutralMinionsKilledYourJungle] => 6 [totalTimeCrowdControlDealt] => 183 ) ) Edited April 7, 2014 by iplaylol Quote Link to comment https://forums.phpfreaks.com/topic/287548-curl-function/#findComment-1475203 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.