Jump to content

cURL function


iplaylol

Recommended Posts

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?

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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 by iplaylol
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.