亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

PHP - 如何通過流 url 的公共部分匹配來自兩個 m3u8 播放列表的流?

PHP - 如何通過流 url 的公共部分匹配來自兩個 m3u8 播放列表的流?

PHP
呼喚遠方 2023-04-21 10:54:02
我有兩個 m3u8 播放列表,其中包含許多我試圖匹配在一起的流。來自 Playlist01 的每個鏈接在第二個鏈接中都有它的一對 - Playlist02 并且每一對都有一個公共頻道 ID,我想通過它進行匹配。Playlist01 包含如下鏈接:#EXTM3U#EXTINF:-1 tvg-id="Name01" tvg-logo="http://link.png" tvg-chno="100" group-titles="groupone", Name01path/playlist.php?ch=5101-ab#EXTINF:-1 tvg-id="Name02" tvg-logo="http://link.png" tvg-chno="160" group-titles="groupone", Name02path/playlist.php?ch=5102-ab#EXTINF:-1 tvg-id="Name03" tvg-logo="http://link.png" tvg-chno="650" group-titles="groupone", Name03path/playlist.php?ch=6234-ab然后是帶有鏈接的 Playlist02,例如:#EXTM3U#EXTINF:-1 tvg-id="Name01" tvg-logo="http://link.png" tvg-chno="100" group-titles="groupone", Name01http://link345/at/a31350ff5/857183/5101-ab.m3u8#EXTINF:-1 tvg-id="Name02" tvg-logo="http://link.png" tvg-chno="160" group-titles="groupone", Name02http://link574/at/bn350frf5/675494/5102-ab.m3u8#EXTINF:-1 tvg-id="Name03" tvg-logo="http://link.png" tvg-chno="650" group-titles="groupone", Name03http://link674/at/g4K7J7h0r/845987/6234-ab.m3u8當然還有一些 Playlist.php,它可以幫助我將來自兩個播放列表的鏈接配對在一起。在 Playlist.php 中,我從 Playlist02 讀取數據<?php$string = file_get_contents('playlist02.m3u8'); // reading data from playlist02preg_match_all('/(?P<tag>#EXTINF:-1)|(?<link>http[^\s]+)/', $string, $match ); // parsing data – I want to get just the url links$count = count( $match[0] );$result = [];$index = -1;for( $i =0; $i < $count; $i++ ){    $item = $match[0][$i];    if( !empty($match['tag'][$i])){        //is a tag increment the result index        ++$index;    }elseif( !empty($match['link'][$i])){        $result[$index]['link'] = $item ;    }}print_r( $result );
查看完整描述

1 回答

?
慕姐8265434

TA貢獻1813條經驗 獲得超2個贊

如果您已經擁有來自 GET 參數的頻道,并且您想要將其鏈接到數組中的一個 url,您可以使用preg_grep。

您可以縮短正則表達式以從 playlist02 匹配 .m3u8 結尾的 url 獲取鏈接

(?<link>http\S+\.m3u8)

然后使用以.m3u8結尾的模式中的 $channel 在 playlist01 的 url 列表中搜索,就像斷言字符串結尾的$channel\.m3u8$地方一樣。$

示例代碼

$playlist02 = file_get_contents('playlist02.m3u8');

preg_match_all('/(?<link>http\S+\.m3u8)/', $playlist02, $matches);

$channel = preg_quote("5101-ab");

$pattern = "/$channel\.m3u8$/";

$result = preg_grep($pattern, $matches["link"]);

var_export($result);

輸出


array (

? 0 => 'http://link345/at/a31350ff5/857183/5101-ab.m3u8',

)


查看完整回答
反對 回復 2023-04-21
  • 1 回答
  • 0 關注
  • 172 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號