2013-12-18 53 views
0

我想排序pubdate的我的RSS提要,但直到如今unsuccesfully 我已經試過usort方法,但我不能得到的代碼工作排序RSS提要通過pubdate的在PHP

我實際的RSS頁面鏈接click here

,這裏是我的PHP代碼,顯示飼料頁面

<?php 
$rssfeed = "<?xml version='1.0' encoding='ISO-8859-1'?> 
<rss version='2.0'> 
<channel> 
     <title>My RSS feed</title> 
     <link>http://" . $_SERVER['HTTP_HOST'] . "/</link> 
     <description>This is an example RSS feed</description> 
     <language>en-us</language> 
     <copyright>Copyright (C) 2009 mywebsite.com</copyright> 
"; 
$links = scandir('pages/'); 
$links = array_diff($links, array('.', '..', 'subpages', 'protected')); 
foreach($links as $link){ 
$descr = file_get_contents('description/' . $link); 
$descr = str_replace(array('\\'), array(''), $descr); 
$pub = date ('Y m d Hi:s', filemtime('pages/'.$link)); 
    $rssfeed .= "<item> 
      <title>".$link."</title> 
<description>".$descr."</description> 
<link>http://" . $_SERVER['HTTP_HOST'] . "/index.php?p=".$link."</link> 
      <pubDate>".$pub."</pubDate> 
       </item>"; 
} 

$links = scandir('pages/subpages/'); 
$links = array_diff($links, array('.', '..')); 
foreach($links as $link){ 
$descr = file_get_contents('description/' . $link); 
$descr = str_replace(array('\\'), array(''), $descr); 
$pub = date ('Y m d Hi:s', filemtime('pages/subpages/'.$link)); 
    $rssfeed .= "<item> 
      <title>".$link."</title> 
<description>".$descr."</description> 
<link>http://" . $_SERVER['HTTP_HOST'] . "/index.php?p=".$link."</link> 
      <pubDate>".$pub."</pubDate> 
       </item>"; 
} 
    $rssfeed .= "</channel></rss>"; 
echo $rssfeed; 
?> 

我usort財產以後嘗試過像

function cmp($pub, $b) 
{ 
    if ($pub == $b) { 
     return 0; 
    } 
    return ($pub < $b) ? -1 : 1; 
} 
usort($a, "cmp"); 

我不能得到它的工作。有什麼想法嗎?所有幫助是非常讚賞

回答