3v4l.org

run code in 300+ PHP versions simultaneously
<?php $m3u = '#EXTM3U #EXTINF:0 tvg-name="BBC" audio-track="eng" tvg-logo="http://mylogos.domain/BBC.png", BBC World http://server.name/stream/to/video2 #EXTINF:0 tvg-name="CNN" audio-track="rus", CNN International http://server.name/stream/to/video2 #EXTINF:0, Arirang http://server.name/stream/to/video3 #EXTINF:-1 tvg-id="http://www.arte.tv/" tvg-name="|ALLEMAGNE| ARTE ASTRA 19.2" tvg-logo="http://192.168.1.150/logotheque/arte_de.png" group-title="CULTURE ALLEMAGNE ASTRA 19.2",|ALLEMAGNE| ARTE ASTRA 19.2 http://192.168.1.150/1258'; $pattern = '~(*BSR_ANYCRLF) ^ \Q#EXTINF:\E (?<length> 0 | -1 | [1-9][0-9]* ) [ ]* (?<attributes> (?: [ ]* [\w-]+ =" [^"]* " \B )+ )? , [ ]* (?<title> .* \S ) [ ]* \R (?<url> .* \S ) ~xum'; preg_match_all($pattern, $m3u, $matches, PREG_SET_ORDER | PREG_UNMATCHED_AS_NULL); $results = []; $keys = array_flip(['length', 'attributes', 'title', 'url']); foreach($matches as $m) { if ( $m['attributes'] !== null ) { preg_match_all('~(?<name> [\w-]+ ) = " (?<value> [^"]* ) " ~x', $m['attributes'], $attr); $m['attributes'] = array_combine($attr['name'], $attr['value']); } $results[] = array_intersect_key($m, $keys); } print_r($results);

preferences:
26.82 ms | 402 KiB | 5 Q