English 中文(简体)
PHP 按日期排序函数( JWPLAYER 自动播放列表脚本)
原标题:PHP Sort function by date (JWPLAYER auto playlist script)
  • 时间:2012-05-25 09:24:45
  •  标签:
  • php
  • jwplayer

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

我要补充一个我无法解决的功能。

我要点名或日期的播放列表。

 $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 和列表之前,我想在上述代码中添加一个排序函数。

谢谢 谢谢

最佳回答

您必须绕过目录, 并用 filemtime 获取日期, 然后以一个数组中丢弃日期, 这里是一个工作脚本, 您可以更改 $path, $xmlfile 或 arsort () 来根据您的需要排序( ) 。

<?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);
?>
问题回答

使用文件名、日期时间( 使用 filemtime( $file) ) 等编组, 并相应排序 。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签