简体   繁体   中英

url + variable in a curlopt_url

so i have this code

foreach ($listGame->response as $app) {
              $gameName = curl_init();
              curl_setopt($gameName, CURLOPT_URL, 'https://itunes.apple.com/lookup?id=' + $app->AppID);
              curl_setopt($gameName, CURLOPT_RETURNTRANSFER, TRUE);
              $gameNameRes = json_decode(curl_exec($gameName)) ;
              curl_close($gameName);
              $gameNameResults = $gameNameRes->results;

this is a loop, so there is a big API of apps, as this is a loop, what i want the code to do is,retrieve the app info from the appstore using the appID specified in the API. problem is, trying this code makes the site inaccessible, will not load, i dont know if this is because $listGame-response is indeed the API response from a cURL request i did earlier, maybe doing a cURL request and then looping through cURL requests is not the best idea, but i need to grab the info from the appstore from each app in the API

The problem is, that you use + instead of . to add the get param to the url given to curl. Just replace + with . and the url should be correct

'https://itunes.apple.com/lookup?id=' . $app->AppID

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM