PHP按日期排序功能(JWPLAYER自动播放列表脚本) [英] PHP Sort function by date (JWPLAYER auto playlist script)

查看:115
本文介绍了PHP按日期排序功能(JWPLAYER自动播放列表脚本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这将帮助具有JWPLAYER的任何人通过扫描文件夹并自动创建正确的XML文件来制作播放列表.

This will help anyone with JWPLAYER to make a playlist by scanning a folder and creating the correct XML file automatically.

我想添加一个我无法解决的功能.

I would like to add one function which I can not work out.

我想按名称或日期订购播放列表.

I would like to order the play list by name or date.

 $folder = opendir($path);
$start="<asx version='3.0'>n<title>Example ASX playlist</title>";
$Fnm = "./playlist.xml";
$inF = fopen($Fnm,"w");
fwrite($inF,$start."n");
while( $file = readdir($folder) ) {
     if (($file != '.')&&($file != '..')&&($file != 'index.htm')){
     $result="<entry>n<title>$file</title>n<ref href='$path2$file'/>n<param name='image' value='preview.jpg'/>n</entry>n";
         fwrite($inF,$result);
     }
}
fwrite($inF,"</asx>");
closedir($folder);
fclose($inF);
?>

问题:

我想在创建XML和列表之前按日期在上面的代码中添加一个排序功能.

I would like to add to the above code a sort function by date before creating the XML and list.

谢谢

推荐答案

您必须循环目录并使用filemtime获取日期并将其转储到数组中,这是一个有效的脚本,您可以更改$ path,$ xmlfile或arsort()到s​​ort()取决于您的需要...

You have to loop the directory and get the date with filemtime and dump it in an array, here's a working script, you may change $path,$xmlfile or arsort() to sort() depanding on your needs ...

<?php

$xmlfile = "playlist.xml";
$path = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']). "/musicfolder";
$folder = scandir($path);
$files = array();
foreach($folder as $file){
    if($file == '.' OR $file == '..' OR $file == 'index.htm'){}else{
        $files[$file] = filemtime($path.'/'.$file);
    }
}
arsort($files);

//use asort to sort from old to new

$output="<asx version='3.0'>" . PHP_EOL . "<title>Example ASX playlist</title>";
foreach($files as $file => $date){
$output .= "<entry>" . PHP_EOL . "<title>$file</title>" . PHP_EOL . "<ref href='$path'/>" . PHP_EOL . "<param name='image' value='preview.jpg'/>" . PHP_EOL . "</entry>" . PHP_EOL;
}
$output .= "</asx>";
file_put_contents($xmlfile,$output);
?>

这篇关于PHP按日期排序功能(JWPLAYER自动播放列表脚本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆