例如,我在以下变量中有四个链接:
$content = "
http://example.com/folder/Name.S01E01.720p.mp4
http://example.com/folder/Name.S01E02.720p.mp4
http://example.com/folder/Name.S02E01.480p.mp4
http://example.com/folder/Name.S02E02.480p.mp4
";
在up变量中,我想根据几句话创建一个订单:
Season template is S00 And Episode template is E00 And Quality template is 720p and 480p
所以,我需要结合这些值以获得结果,
我需要一些函数来使$ content变成这样:
Array
(
[01] => //Season Number
(
[720p] =>//Quality Name
(
[URLs] => //Full Url's
(
[0] => http://example.com/folder/Name.S01E01.720p.mp4
[1] => http://example.com/folder/Name.S01E02.720p.mp4
)
)
)
[02] => //Season Number
(
[480p] => //Quality Name
(
[URLs] => //Full Url's
(
[0] => http://example.com/folder/Name.S02E01.480p.mp4
[1] => http://example.com/folder/Name.S02E02.480p.mp4
)
)
)
)
希望您能理解我的意思。
请看这个:
$content = "
http://example.com/folder/Name.S01E01.720p.mp4
http://example.com/folder/Name.S01E02.720p.mp4
http://example.com/folder/Name.S02E01.480p.mp4
http://example.com/folder/Name.S02E02.480p.mp4
";
if(preg_match_all('/(https?:\/\/[^ ]+?(?:\.mkv|\.mp4))/ms', $content, $matches)){
foreach($matches[0] as $link){
if(preg_match('/(\d++(p))/i',$link,$q)){
$quality[] = $q[0];
}
$full_url[] = trim(urldecode($link));
}
}
if(preg_match_all('/(S(\d++)E(\d++))/i', $content, $parts)){
foreach($parts[0] as $part){
$season[] = $part[2];
}
}
//var_dump($quality);
//var_dump($full_url);
//var_dump($season);
我想将$ season与$ full_url和$ quality结合起来。
答案 0 :(得分:1)
我添加了名称部分作为第一级,并为每个URL添加了情节编号而不是动态索引,如果您不希望使用它们,则只需使用$result[$m[2]][$m[4]]['URLs'][] = $url;
。如果您还有其他扩展名,我也省略了.mp4
部分:
$lines = array_filter(explode("\n", $content));
foreach($lines as $url) {
preg_match('/^([^.]+)\.S(\d\d)E(\d\d)\.(\d+p)/', pathinfo($url, PATHINFO_BASENAME), $m);
$result[$m[1]][$m[2]][$m[4]]['URLs'][$m[3]] = $url;
}
鉴于您的$content
,将产生以下内容:
Array
(
[Name] => Array
(
[01] => Array
(
[720p] => Array
(
[URLs] => Array
(
[01] => http://example.com/folder/Name.S01E01.720p.mp4
[02] => http://example.com/folder/Name.S01E02.720p.mp4
)
)
)
[02] => Array
(
[480p] => Array
(
[URLs] => Array
(
[01] => http://example.com/folder/Name.S02E01.480p.mp4
[02] => http://example.com/folder/Name.S02E02.480p.mp4
)
)
)
)
)
^
开始匹配,并捕获一个或多个+
非点[^.]
字符\.
与字母S
匹配,并捕获两位数字\d\d
E
并捕获两位数字\d\d
\.
,并捕获一个或多个数字\d+
和p
字符