title: Php Curl parsing a m3u file on array
body: <p>Hope you can help me out.
  I have got abc.m3u file which contains for example:</p>
  
  <pre><code>#EXTM3U
  
  #EXTINF:-1,CH1
  
  https://fakedummy.net/tre002/55D6D-channel7/1.m3u8
  
  #EXTINF:-1,CH2
  
  https://fakeone.net/teb002/12333-channel8/1.m3u8
  
  #EXTINF:-1,CH3
  
  http://fake.fake/tv/m3u8/fake.m3u8?id=fake_abc
  
  #EXTINF:-1,CH4
  
  http://test.test:13000/xxx/jgjkg/671.ts
  </code></pre>
  
  <p>Could anyone kindly show me how can i parse this whole file m3u (it's a pretty large one) on php array,to be able later to play the output later on vlc , ffmpeg or any player on format of:</p>
  
  <pre><code>http://localhost/myphpfile.php?id=CH1 &gt;to play first stream on abc.m3u file 
  https://fakedummy.net/tre002/55D6D-channel7/1.m3u8
  
  http://localhost/myphpfile.php?id=CH2 &gt;to play 2nd stream on abc.m3u file
  https://fakeone.net/teb002/12333-channel8/1.m3u8
  
  http://localhost/myphpfile.php?id=CH3 &gt;to play 3rd stream on abc.m3u file
  http://fake.fake/tv/m3u8/fake.m3u8?id=fake_abc
  
  http://localhost/myphpfile.php?id=CH4 &gt;to play 4th stream on abc.m3u file
  http://test.test:13000/xxx/jgjkg/671.ts
  </code></pre>
  
  <p>I had try it out the below code and it is working only for the first chl only</p>
  
  <pre><code>    &lt;?php
      $handle = curl_init();
      $url = "abc.m3u";
      $domain = preg_replace("(^https?://)", "", $url );
      $header = array('Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3');
     curl_setopt($handle, CURLOPT_URL, $url);
     curl_setopt($handle, CURLINFO_HEADER_OUT, 1);
     curl_setopt($handle, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Ubuntu; Linux 
     x86_64; rv:55.0) Gecko/20100101 Firefox/55.0.1');
     curl_setopt($handle, CURLOPT_FOLLOWLOCATION, false);
     curl_setopt($handle, CURLOPT_NOSIGNAL, true);
     curl_setopt($handle, CURLOPT_RETURNTRANSFER, false); 
     curl_setopt($handle, CURLOPT_HTTPHEADER, $header); 
     curl_setopt($handle, CURLOPT_HEADER, false);
     curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
  
     $result = curl_exec($handle);
     curl_close($handle);
     // var_dump($result);
     print_r($result);
  
     $channel = 'CH1';// This is a channel you want to watch 
     $list = explode(PHP_EOL, $result);
     for ($i = 0; $i &lt; count($list); ++$i){
     if ((strpos($list[$i], $channel) !== false) &amp;&amp; ($i + 1 &lt; count($list))) {
      echo $list[$i+1];
      break;
  } 
     }
    ?&gt;
  </code></pre>
  
  <p>Could you please help me with with update for my code?
  Thanks in advance</p>