在PHP rss中格式化TimeStamp

时间:2011-11-29 20:24:44

标签: php css wordpress rss

我的Wordpress网站上有一个简单的RSS源,但需要设置样式和格式化。而且我特别挣扎着格式化'时间戳'。

以下是我的代码,任何帮助都很棒 -

PHP位于文档顶部。

<?php
$doc = new DOMDocument();
$feedURL = 'http://www.mysite.net/feed/';
$doc->load($feedURL);
//$doc->setEncoding("UTF8");
$itemsArray = array();

$items = $doc->getElementsByTagName( "item" );
$itemCounter = 0;
foreach($items as $item) {
    $titleInfo = array();
    $titles = $item->getElementsByTagName( "title" );
    $title = $titles->item(0)->nodeValue;

    $timestamps = $item->getElementsByTagName( "pubDate" );
    $timestamp = $timestamps->item(0)->nodeValue;   

    $totalItems = 4;
    if($itemCounter < $totalItems) {                
        $links = $item->getElementsByTagName("link");
        $link = $links->item(0)->nodeValue;                     
        array_push($titleInfo, $title, $link,  $timestamp, $itemCounter);  
        array_push($itemsArray, $titleInfo);
        $itemCounter++;                         
        }
}

?>

<?php
    include('../includes/db-connect.php');
    include('../includes/queries.php');
    include('../includes/imprintArray.php');        
    $imprintChoice = 'tenspeed';
    $imprintVar = $imprintChoice;
    $shortImprint = $imprintarray[$imprintChoice]["shortImprint"];
    $imprintCode = $imprintarray[$imprintChoice]["imprintCode"];
    $imprintName = $imprintarray[$imprintChoice]["imprintName"];
    $imprintColor = $imprintarray[$imprintChoice]["imprintColor"];
    $results_sort='pub_date';
?>

以下是加价:

<!--New RC feed area 1121-->

        <div id="RCbox" style="height:auto; width:100%; background-color:#fff;">

        <div class="rightside_titlebox" style=" width: 100%; background: none repeat scroll 0% 0% rgb(255, 159, 35);">
        <h1 class="rightside_title">Latest from Recipe Club</h1>
        </div> 

        <div style="float:left; width:360px; padding:10px; line-height:25px;">


   <a href="<?php echo $titleInfo[1]; //LINK ?>" style="color: #466289; font-weight: bold;"><?php echo $titleInfo[0]; //POST TITLE ?></a></p><br />

   <?php
    foreach($itemsArray as $titleInfo) {            
        ?><br />            
       <p><?php echo $titleInfo[2];//TIMESTAMP ?>         
        <?php } ?>



        </div>

        <div style="float:right; width: 360px; text-align:center;"> 

        <p style="margin-top:-80px;">[ Logo Here ]</p>

        </div>           

        </div>

        <br />

        <!--End RC area-->

Feed有效,但看起来像:

星期二,2011年11月29日15:07:22 +0000 Giada at Home的意大利面Ponza

我希望它的格式如下:

发布于2011年11月29日

1 个答案:

答案 0 :(得分:2)

您只是从Feed中输出确切的值。

您首先要转换它,例如:

$timestamp = date('F jS, Y', strtotime($timestamps->item(0)->nodeValue));