88 lines
2.5 KiB
PHP
88 lines
2.5 KiB
PHP
<?php
|
|
error_reporting(E_ALL);
|
|
ini_set("display_errors", 0);
|
|
function truncate($str, $width) {
|
|
return strtok(wordwrap($str, $width, "...\n"), "\n");
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$ch = curl_init();
|
|
|
|
// set url
|
|
curl_setopt($ch, CURLOPT_URL, "https://www.thebatorblog.com/feed/");
|
|
|
|
//return the transfer as a string
|
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
// $output contains the output string
|
|
$output = curl_exec($ch);
|
|
|
|
|
|
|
|
// close curl resource to free up system resources
|
|
curl_close($ch);
|
|
|
|
|
|
$file = 'xml.txt';
|
|
// Open the file to get existing content
|
|
$current = file_get_contents($file);
|
|
// Append a new person to the file
|
|
$current .= "John Smith\n";
|
|
// Write the contents back to the file
|
|
file_put_contents($file, $output);
|
|
|
|
$xml=simplexml_load_file($file, 'SimpleXMLIterator');
|
|
|
|
|
|
$items = new LimitIterator($xml->channel->item, 0, 4);
|
|
$i = 0;
|
|
echo '<rss version="2.0"
|
|
xmlns:content="http://purl.org/rss/1.0/modules/content/"
|
|
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
|
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
|
xmlns:atom="http://www.w3.org/2005/Atom"
|
|
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
|
|
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
|
|
xmlns:media="http://search.yahoo.com/mrss/">
|
|
|
|
<channel>
|
|
<title>TheBatorBlog</title>
|
|
<atom:link href="https://www.thebatorblog.com/feed/" rel="self" type="application/rss+xml" />
|
|
<link>https://www.thebatorblog.com</link>
|
|
<description>The Bate Goes On</description>
|
|
<lastBuildDate>Sat, 22 Apr 2017 21:34:39 +0000</lastBuildDate>
|
|
<language>en-US</language>
|
|
<sy:updatePeriod>hourly</sy:updatePeriod>
|
|
<sy:updateFrequency>1</sy:updateFrequency>';
|
|
foreach ($items as $item) {
|
|
$i = $i + 1;
|
|
$titleRaw = (string) $item->title; // Title Post
|
|
$title = ucwords(strtolower(str_replace("&", "&", $titleRaw)));
|
|
|
|
$link = (string) $item->link; // Url Link
|
|
$link1=explode("?", $link);
|
|
$link =$link1[0];
|
|
$pubDate = (string) $item->pubDate; // date
|
|
$descriptionFull = (string) str_replace("&", "&", $item->description); //Description Post
|
|
$imgPost = (string) $item->url; // post image
|
|
|
|
$description = truncate(strip_tags($descriptionFull), 100);
|
|
|
|
|
|
echo '
|
|
<item>
|
|
<title>'.$title.'</title>
|
|
<link>'.$link.'</link>
|
|
<comments>'.$link.'#comments</comments>
|
|
|
|
|
|
<description>'.$description.'</description>
|
|
<url>'.$imgPost.'</url> </item>';
|
|
}
|
|
?></channel>
|
|
</rss>
|