- file_get_contents: documentation ( source)
- json_decode: documentation ( source)
- rawurlencode: documentation ( source)
- sprintf: documentation ( source)
<?php
$stream = 'skwjr';
$url = sprintf('https://api.twitch.tv/api/channels/' . $stream . '/access_token/');
$page = file_get_contents($url);
$json = json_decode($page, true);
$token = $json['token'];
$sig = $json['sig'];
echo 'http://usher.twitch.tv/api/channel/hls/' . $stream . '.m3u8?player=twitchweb&token=' . rawurlencode($token) . '&sig=' . $sig;