使用 html 元素和 css 样式自定义 php RSS 提要

Customize a php RSS feed with html elements and css styling

我使用 PHP.

将 RSS 提要集成到我的网站中

我正在尝试弄清楚如何使用 echo 'html code' 或类似的东西来格式化我的 php 中有 html 标签的地方,以便我可以设置这些 html 个带有 CSS 的元素,因为 php 不能单独设置样式(至少根据我所做的研究)。我不确定整合 html 元素的最佳方法是什么,但我的大部分错误都来自

$html .= ""

RSS Feed 当前看起来像这样

我想做 3 件事:
1. 将日期设为月、日和年。 (去掉开头的星期几和结尾的时间 & +0000,例如 2016 年 6 月 13 日)

2.Change 标题的颜色(新闻文章的标题不是 "LMHS News"。

  1. 在每篇新闻文章标题周围添加一个 link 最好是 a href="" 标签。

这是源代码

<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>

我想通了!我设置了一个默认时区,然后没有将 pubDate 添加到页面,而是提取了 pubDate 信息,然后使用 "strftime" 和 "strtotime" 按照我想要的方式格式化 pubDate。然后通过设置 links 的样式,我将 link 和标题添加到每篇文章中,并创建了一个名为 $linkedTitle 的变量,您可以在下面看到它。从那里我可以按照我想要使用 CSS 的方式设置 link 的样式。我把它包裹在一个名为 #widgetmain 的 div 中,所以我在 CSS 中选择了 links 和 #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;


            ?>