3v4l.org

run code in 300+ PHP versions simultaneously
<?php $apiKey = 'AIzaSyC7udxUIPhN213ilX9Reyc_ZzXN5_id5eg'; $channelId = 'UC226a2gZas0iS2KUtrF7oFw'; $maxResults = 50; $results = fetchLists($apiKey, $channelId, $maxResults); function fetchLists($apiKey, $channelId, $maxResults, $listsNextPage = null, $playlists = array()) { $ytApiUrl = 'https://www.googleapis.com/youtube/v3/playlists?maxResults=' . $maxResults . '&part=snippet&channelId=' . $channelId . '&key=' . $apiKey ; if($listsNextPage !== null){ $ytApiUrl .= '&pageToken=' . $listsNextPage; } $jsonLists = json_decode(file_get_contents($ytApiUrl)); $listsPageToken = (isset($jsonLists->nextPageToken)) ? $jsonLists->nextPageToken : null ; foreach ($jsonLists->items as $item) { $plId = $item->id; $list = array( "id" => $plId, "title" => $item->snippet->title, "published" => $item->snippet->publishedAt, "url" => 'https://www.youtube.com/playlist?list=' . $plId, "thumbnail" => $item->snippet->thumbnails->default->url, "videos" => [] ); fetchVideos($list, $playlists, $maxResults, $plId, $apiKey); } if($listsPageToken !== null){ return fetchLists($apiKey, $channelId, $maxResults, $listsPageToken, $playlists); } return $playlists; } function fetchVideos(&$list, &$playlists, &$maxResults, &$plId, &$apiKey, $vidsNextPage = null) { $plApiUrl = 'https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults='. $maxResults .'&playlistId=' . $plId . '&key=' . $apiKey; if($vidsNextPage !== null){ $plApiUrl .= '&pageToken=' . $vidsNextPage; } $jsonPlVideos = json_decode(file_get_contents($plApiUrl)); $videosPageToken = (isset($jsonPlVideos->nextPageToken)) ? $jsonPlVideos->nextPageToken : null ; foreach ($jsonPlVideos->items as $vid) { $video = array( "title" => $vid->snippet->title, "url" => 'https://www.youtube.com/watch?v=' . $vid->snippet->resourceId->videoId, "published" => $vid->snippet->publishedAt, "thumbnail" => $vid->snippet->thumbnails->default->url ); $list['videos'][] = $video; } $playlists[] = $list; if($videosPageToken !== null){ return fetchVideos($list, $playlists, $maxResults, $plId, $apiKey, $videosPageToken); } }
Output for git.master, git.master_jit, rfc.property-hooks
Warning: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in /in/qe40e on line 14 Warning: file_get_contents(): open_basedir restriction in effect. File(https://www.googleapis.com/youtube/v3/playlists?maxResults=50&part=snippet&channelId=UC226a2gZas0iS2KUtrF7oFw&key=AIzaSyC7udxUIPhN213ilX9Reyc_ZzXN5_id5eg) is not within the allowed path(s): (/tmp:/in:/etc) in /in/qe40e on line 14 Warning: file_get_contents(https://www.googleapis.com/youtube/v3/playlists?maxResults=50&part=snippet&channelId=UC226a2gZas0iS2KUtrF7oFw&key=AIzaSyC7udxUIPhN213ilX9Reyc_ZzXN5_id5eg): Failed to open stream: Operation not permitted in /in/qe40e on line 14 Warning: Attempt to read property "items" on null in /in/qe40e on line 16 Warning: foreach() argument must be of type array|object, null given in /in/qe40e on line 16

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
59.09 ms | 403 KiB | 8 Q