Auref Pourkarimi Auref Pourkarimi - 5 months ago 355
PHP Question

How i extract m3u8 of this url by regex?

I want to extract m3u8?id= of this link :
http://www.filmon.com/api-v2/channel/11

result of extract to be this : http://204.107.27.237/live/11.high.stream/playlist.m3u8?id=035bca1a71b11fce016d28acd...

and this is my code but it doesn't work:

<?php
$streamSite = "http://www.filmon.com/api-v2/channel/11";

function writeFile($url, $channel) {
$File = $channel.".strm";
$Handle = fopen($File, 'w');
fwrite($Handle, $url);
fclose($Handle);
}

$input = @file_get_contents($streamSite) or die("Could not access file: $url");

preg_match("/(id\=[^\&\">]+)/", $input, $matches);

echo $matches[1];

?>

Answer

If I understood correctly your question, you want to capture the full link from the url content using regex.

You can use this regex then:

(http.*?id=[^"]*)

Working demo

Match information

MATCH 1
1.  [665-1042]  `http://live-1273.fra.edge.filmon.com/live/11.low.stream/playlist.m3u8?id=035bca1a71b11fce016d28acd3dbea51cbc96ddfe5b9ed3f8fe3286df6a738d305b8f0fdece6009826a3adcf0a7eab3e005f7ab88aa0a049afc469c64746be364a67c6ea610df29323457950eb12912a0f1dc1a1d39f76de63b66368343adcd6596bdc286e79eafebcc9baf840d12df239767a6a05ef355fa88beb2ab2a99ef3af96aafc9142ee35ef97655c122c7fa02726c6f806264a54`