Tested and working :)
Steps :
- Remove all spaces.
- Split when there is a ",".
- Create an array and fill it only with url finishing with .m3u8.
- You get your ".m3u8" urls :).
<?php
$string = "http://exemple.com/file/01.mp4 ,http://exemple.com/file/02.m3u8 , http://exemple.com/file/01.mp3 ,http://exemple.com/file/05.m3u8 ,http://exemple.com/file/02.mp4" ;
$string = str_replace(' ', '', $string);
$urls = explode( ",", $string);
$result = [];
foreach ($urls as $url){
if( substr($url, -5) == ".m3u8") array_push($result, $url);
}
var_dump($result);