Итак, я написал Reader для RSS-канала в PHP, и я почти закончил (я думаю), но я еще не дошел до той части, где я могу фильтровать ключевые слова. Когда я попытался это исправить, он сказал, что в конце файла отсутствует символ "}". Я не уверен, что делать с этой проблемой, поэтому я здесь. Я использую код Visual Studio, и любая помощь будет высоко ценится.
Вот код, который я написал:
<?php
/*
* To access the localhost for this program type in the address bar: "localhost/feedreader" then
* click on RSSFeedReader.php when you install the two files by the names of "RSSFeedReader.php" and "RSSConfig.json" into the Sites
* folder in the Users section.
*/
?>
<div class="content">
<form method="post" action="">
<input type="text" name="feedurl" placeholder="Enter website RSS Link"> <input type="submit" value="Submit" name="submit">
</form>
<div class="content">
<form method="post" action="">
<input type="text" name="keyword" placeholder="Enter keyword here"> <input type="submit" value="Submit" name="submit">
</form>
<?php
/*
The piece of code above will create the box that says "Enter Website RSS Link" and the submit
button that will process through the code to search the inputted RSS link.
Line 1 will create the div class in which the content of the client side of things(Front-End),and the form POST method is a way of
retrieving information and data that is being inputted through the sumbit section
*/
if(isset($_POST['submit'])){
if($_POST['feedurl'] != ''){
$url = $_POST['feedurl'];
}
}
$invalidurl = false;
if(@simplexml_load_file($url)){
$feeds = (simplexml_load_file($url));
}
else{
$invalidurl = true;
echo "<h2>Invalid RSS Feed Link.
Please try a valid RSS Feed Link.
</h2>";
}
/*
This block of code above generally allows the screen to output "Invalid RSS Feed Link. Please try a valid RSS Feed Link."
when typing out a URL/XML link which is not an RSS Feed Link.
First, the program will assign the variable: $invalidurl to false and will load the simple xml file, however if the url turned out
to be invalid, the program will output "Invalid RSS Feed Link" to the user's screen.
The first line will assume that the is no invalid url link so it is assigned to be false, then the simplexml_load_file will load
up the xml files and if the url is a feed link, it will store the the link into the variable "$feeds". However, if the url is
not a feed link, then it will make the program assign the variable "$invalidurl" as true which will the return the string "Invalid
RSS Feed Link. Please try a valid RSS Feed Link" with a level 2 headline.
*/
$i=0;
if(!empty($feeds)){
$site = $feeds->channel->title;
$sitelink = $feeds->channel->link;
if(isset($_POST['submit'])){
if($_POST['keyword'] != ''){
string == $_POST['keyword'];
}
}
function parse($xml)
{
return [
'title' => (string) $xml->channel->title
];
}
}
echo "<h1>".$site."</h1>";
foreach ($feeds->channel->item as $item) {
$title = $item->title;
$link = $item->link;
$description = $item->description;
$postDate = $item->pubDate;
$pubDate = date('D, d M Y',strtotime($postDate));
/*
The block of code from line 67 to line 71 represent how the program will extract the dtaa from the article in terms
of the title, a hyperlink, the description of the article, and the date that that the article was published(Day, Month and Year)
The first line sets the variable "$i" is set to zero which identifies future into the code how many results the program will output
onto the results page.
Then the next two lines of code will represents how the program will extract the title of the artcile by going though the page
source and into the feed area where the title is stored. It then gets the link to the article to make make the title a hyperlink.
the next piece of code from line 75 to 79 will store the title of the articel into the variable "$title" as an item. It will also
store the link of the article into the variable "$link" as an item. It will also store what the page source identitifies as the
description of the article into the variale "$description" as an item. It wil also the extract the date that the article was
published from the "pubDate" in the page source as the variable "$postDate". the $pubDate will store the postDate in terms of
days, months and years.
*/
if($i>=15) break;
?>
<div class="post">
<div class="post-head">
<h2><a class="feed_title" href="<?php echo $link; ?>"><?php echo $title; ?></a></h2>
<span><?php echo $pubDate; ?></span>
</div>
<div class="post-content">
<?php echo implode(' ', array_slice(explode(' ', $description), 0, 20)) . "..."; ?> <a href="<?php echo $link; ?>">Read more</a>
</div>
</div>
<?php
$i++;
if(!$invalidurl){
echo "<h2>No item found</h2>";
}}
?>