Formatting TimeStamp in PHP rss
I have a simple RSS feed coming in my Wordpress site with php, but need to style and format it. And am particularly struggling with formatting the 'time stamp'.
Below is my code, any help is awesome -
PHP at the top of doc.
<?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'; ?>
Below is the mark-up:
<!--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-->
The feeds working, but appears looking like:
Tue, 29 Nov 2011 15:07:22 +0000 Pasta Ponza from Giada at Home
And I'd like it to be formatted like:
Posted on November 29th, 2011
Answers
You're simply outputting the exact value from the feed.
You'll want to convert it first, with something like :
$timestamp = date('F jS, Y', strtotime($timestamps->item(0)->nodeValue));