Ryan
Ryan

Reputation: 6217

Reformat RSS date string with PHP SimpleXML

I'm grabbing our News XML feed and outputting several fields, specifically the date, which outputs like this:

Fri, 20 May 2011 00:00:00 PDT

My question is, how can I reformat the date to this:

Friday, May 20, 2011

Here's my code:

<?php $rss = simplexml_load_file('http://news.stanford.edu/rss/index.xml'); ?>
    <h1><?php echo $rss->channel->title; ?></h1>
    <ul>
        <?php foreach($rss->channel->item as $a) { ?>
        <li>
            <a href="<?php echo $a->link;?>">
                <h3><?php echo $a->title;?></h3>
                <p><strong><?php echo $a->description; ?></strong></p>
                <p><?php echo $a->pubDate; ?></p>
            </a>
        </li>
    <?php } ?>
    <ul>

Upvotes: 2

Views: 1632

Answers (1)

tradyblix
tradyblix

Reputation: 7569

This should do it:

$string = strtotime('Fri, 20 May 2011 00:00:00 PDT');
echo date('l, F j, Y', $string); // Friday, May 20, 2011

So in your code:

<?php echo date('l, F j, Y', strtotime($a->pubDate));?>

Upvotes: 7

Related Questions