0
votes

I have an RSS feed that i've integrated into my website using PHP.

I'm trying to figure out how I can format my php where I have html tags within using echo 'html code' or something similar so that I can style those html elements with CSS because php can't be styled by itself (at least from the research that i've done). I'm not sure what the best way is to integrate the html elements but most of my errors are coming from

$html .= ""

The RSS Feed currently looks like thisCurrent RSS Feed

There are 3 things I want to do:
1. Take date and make it just Month, Day, and year. (get rid of day of week at the beginning and time & +0000 at the end so it's just Jun 13, 2016 for example)

2.Change the color of the titles (The news article's titles not "LMHS News".

  1. Add a link preferably an a href="" tag around each news article title.

Here is the source code

<div class="row">

<div class="col-md-6">

    <div id="news-header">
            <h2 id="lmhs-news">LMHS News</h2> <a href="http://508.63c.myftpupload.com/"><small class="more-news">More</small></a>
      </div>

    <div id="widgetmain">

        <?php

            $html = "";
            $url = "http://508.63c.myftpupload.com/feed/";
            $xml = simplexml_load_file($url);
            for($i = 0; $i < 5; $i++) {
                $date = $xml->channel->item[$i]->pubDate;
                $title = $xml->channel->item[$i]->title;
                $link = $xml->channel->item[$i]->guid;
                $description = $xml->channel->item[$i]->description;
                $html .= "<div>$date
                                    <h3>$title</h3>
                                    $description
                                    </div> 
                                    ";
            }


            echo $html;


            ?>


    </div>

</div>

1

1 Answers

0
votes

I figured it out! I set a default timezone then instead of adding pubDate to the page I pulled the pubDate information then used the "strftime" with "strtotime" to format the pubDate the way I wanted it. Then with styling the links I pulled the link and title to each article and created a variable called $linkedTitle which you can see below. From there I was able to style the links the way I wanted to using CSS. I had this wrapped in a div called #widgetmain so I selected the links in CSS with #widgetmain a { }

<?php

        date_default_timezone_set('America/New_York');
            $html = "";
            $url = "http://508.63c.myftpupload.com/feed/";
            $xml = simplexml_load_file($url);
            for($i = 0; $i < 5; $i++) {
                $pubDate = $xml->channel->item[$i]->pubDate;
                $pubDate = strftime("%b %d, %Y", strtotime($pubDate));
                $title = $xml->channel->item[$i]->title;
                $link = $xml->channel->item[$i]->guid;
                $linkedTitle = "<a href='$link'>$title</a>";
                $description = $xml->channel->item[$i]->description;

                $html .= "<div>$pubDate
                                    <h3>$linkedTitle</h3>
                                    $description
                                    </div> 
                                    ";
            }


            echo $html;


            ?>