My feeds are made with PHP and MYSQL into XML and then feedburner.
My problem is that dlvr.it cannot read new entries everytime I post.
Here's my PHP code:
<?php
include('db.php');
header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">
<channel>
<title>MindWeather Thesis</title>
<description>Latest News from my website</description>
<link>http://www.mindweather.info</link>';
$get_articles = "SELECT Fore_ID, Valid, Synopsis,
DATE_FORMAT(Issued,'%a, %e %b %Y %T') as formatted_date
FROM tblforecast ORDER BY Issued DESC LIMIT 15";
$articles = mysql_query($get_articles) or die(mysql_error());
while ($article = mysql_fetch_array($articles)){
echo '
<item>
<title>'.$article['Valid'].'-hour Forecast</title>
<description><![CDATA['.$article['Synopsis'].']]> </description>
<link>http://mindweather.info/fforecast.php?fore='.$article['Fore_ID'].'</link>
<pubDate>'.$article['formatted_date'].' GMT</pubDate>
</item>';
}
echo '</channel>
</rss>';
?>
The feedburner feed is located at: http://www.mindweather.info/feedz2.php
Your answers would be as of much help. Thanks!
The mechanism to detect new entries in a feed is to identify them using their unique <guid>. Since your feed lacks that element, it's perfectly normal that this service cannot detect new entries.
It's as simple has addding something like : <guid><?php echo $article['Fore_ID']; ?></guid>, assuming of course that the Fore_ID is unique. Add them between the <item> and </item>
You should also make sure each <link> element is unique because this is another way feed readers try to detect new/unique entries when they fail to do so using that <guid> element.
Related
I am trying to create a RSS feed. This is the PHP code for the feed in question below.
<?xml version="1.0" encoding="utf-8" ?>
<?php
include_once 'authorization.php';
header("Content-Type: text/xml; charset=UTF-8");
$demo_id = "1";
$stmt = $mysqli->prepare("SELECT * FROM demo_files WHERE demo_id = ?");
$stmt->bind_param('i', $demo_id);
$stmt->execute();
$result = $stmt->get_result();
while($row = $result->fetch_assoc()) {
$demo_title=$row['demo_title'];
$demo_content=$row['demo_content'];
echo '<rss version="2.0">
<channel>
<title>Liorall</title>
<link>Youtube Tutorial demo</link>
<language>en-us</language>
<item>
<title>'.$post_title.'</title>
<description>'.$post_content.'</description>
</item>
</channel>
</rss>';
}
?>
Am getting this error Extra content at the end of the document
Please how can i fix it.
Thanks in Advance.
You're initialising $demo_title and $demo_content at the top of your loop, but emitting $post_title and $post_content later.
That will generate an undefined variable warning from PHP that will appear in your output stream and your RSS reader is likely to complain about that.
I changed that on my test system and the output now appears well-formed, but it fails the W3C Validator with some other issues you should address.
I have to following code to upload data to a third party. However when I test it in a validator I get the following error:
Undefined root elements:items and text/xml media type is not specific enough.
I have no clue has what I need to change.
Here is the code:
header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8"?>
<items>';
mysql_select_db($database_dconn, $dconn);
$query_feed = "SELECT * FROM dat_table WHERE time BETWEEN (NOW() - INTERVAL 7 DAY) AND NOW()";
$feed = mysql_query($query_feed, $dconn) or die(mysql_error());
while ($row_feed = mysql_fetch_assoc($feed)){
echo'<item>
<name>'.$row_feed['Name'].'</name>
<email>'.$row_feed['email'].'</email>
<date>'.$row_feed['Date'].'</date>
<description>'.$row_feed['Make'].' '.$row_feed['Model'].' '.$row_feed['Type'].'</description>
<logon>'.$row_feed['Logon'].'</logon>
<category>'.$row_feed['Type'].'/'.$row_feed['Make'].'</category>
<product_search_code>'.$row_feed['Product_search_code'].'</product_search_code>
<order_ref>'.$row_feed['Invoice'].'</order_ref>
<product_link>'.$row_feed['Product_link'].'</product_link>
<customer_ref>'.$row_feed['Invoice'].'</customer_ref>
<amount>'.$row_feed['Price'].'</amount>
<currency>GBP</currency>
</item>';
}
echo '</items>
';
This is RSS out put in validator:
<?xml version="1.0" encoding="UTF-8"?>
<items><item>
<name>Name of customer</name>
<email>customer#gmail.com</email>
<date>03/04/2014</date>
<description>Roland FP80BK Piano</description>
<logon>www.pianoandkeyboardshoponline.co.uk</logon>
<category>Piano/Roland</category>
<product_search_code>264</product_search_code>
<order_ref>8336</order_ref>
<product_link>http://www.pianoandkeyboardshop.co.uk/Roland-FP80-Digital-Piano-in-Satin-Black/264</product_link>
<customer_ref>8336</customer_ref>
<amount>1500.00</amount>
<currency>GBP</currency>
</item><item>
next item etc
---
--
</item><items>
Any help is really appreciated.
The text/xml content type is for generic XML documents. For a feed, try using
header('Content-Type: application/rss+xml');
But anyway, in order to create a valid RSS you have to use the correct RSS tags (Something like this). You seem to use a lot of custom tags instead, so I don't know what exactly you need to do. The easiest solution would be to use namespaces for your custom tags, so something like:
header('Content-Type: application/rss+xml');
echo '<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:mytags="http://mytags.something.net">
<channel>
<title>My RSS Title</title>
<description>This is the description for my RSS feed</description>
<link>http://www.someexamplerssdomain.com/main.html</link>
<mytags:items>';
mysql_select_db($database_dconn, $dconn);
$query_feed = "SELECT * FROM dat_table WHERE time BETWEEN (NOW() - INTERVAL 7 DAY) AND NOW()";
$feed = mysql_query($query_feed, $dconn) or die(mysql_error());
while ($row_feed = mysql_fetch_assoc($feed)){
echo '<mytags:item>
<mytags:name>'.$row_feed['Name'].'</mytags:name>
<mytags:email>'.$row_feed['email'].'</mytags:email>
<mytags:date>'.$row_feed['Date'].'</mytags:date>
<mytags:description>'.$row_feed['Make'].' '.$row_feed['Model'].' '.$row_feed['Type'].'</mytags:description>
<mytags:logon>'.$row_feed['Logon'].'</mytags:logon>
<mytags:category>'.$row_feed['Type'].'/'.$row_feed['Make'].'</mytags:category>
<mytags:product_search_code>'.$row_feed['Product_search_code'].'</mytags:product_search_code>
<mytags:order_ref>'.$row_feed['Invoice'].'</mytags:order_ref>
<mytags:product_link>'.$row_feed['Product_link'].'</mytags:product_link>
<mytags:customer_ref>'.$row_feed['Invoice'].'</mytags:customer_ref>
<mytags:amount>'.$row_feed['Price'].'</mytags:amount>
<mytags:currency>GBP</mytags:currency>
</mytags:item>';
}
echo '</mytags:items>
</channel>
</rss>';
You have no xmlns (XML name space) defined. Thus the error is probably due to the fact that the root element items is... not defined, as said in the error message. See this link or that link for explanations on xmlns.
First, to complete the previous answer, after the first echo, add a rss-specific line: echo '<rss version="2.0">';
Second, you either need to add an xmlns definition in the above line echo '<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">'; for example, or to change the root element name. try with channel or feed. Better yet, find a feed which is read by the service you want your feed to be read by, and have a look at the beginning of the file; look for xmlns and root element names.
best,
I am using the following php code to create an XML file:
echo '<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">
<channel>
<title>mytitle</title>
<description>my description</description>
<link>www.mysite.com</link>';
$sql = "SELECT title, description, url, picture, formatted_date
FROM somewhere" ;
$result = mysql_query($sql);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
if(mysql_num_rows($result)>0)
{
while($result_array = mysql_fetch_assoc($result))
{
//timestamp date to xml format
$pubdate = date('D, d M Y H:i:s O', strtotime($result_array[formatted_date]));
echo '
<item>
<title>'.$result_array[title].'</title>
<description>'.$result_array[description].'</description>
<link>'.$result_array[indit_url].'</link>
<pubDate>'.$pubdate.' GMT</pubDate>
<enclosure url="'.$result_array[picture].'" length="1121990" type="image"/>
<image>
<url>'.$result_array[picture].'</url>
<title>image title</title>
<link>'.$result_array[picture].'</link>
<width>111</width>
<height>33</height>
<description>An amazing picture</description>
</image> </item>';
The file created is correctly validated using http://validator.w3.org/, but when i try to use some xml parser like: http://simplepie.org/ the perser are not able to capture the images. Am i using a correct tag to insert image into xml file? Is there any other tags or method to inser images?
Please try escaping the special characters in the image tag.
Use htmlspecialchars on $result_array[picture]
Also, can you show a sample of your rss feed here so that the answer can be more accurate.
I would suggest surrounding the data in an XML escape structure -as such:
<image>
<url><![CDATA[ imagedatagoeshere ]]></content></url>
</image>
However, I'm not familiar with simplepie, so I don't know if that understands CDATA properly.
I've made a simple news script that saves articles to rss which then gets used on the Character Generator Newsticker on TV, the problem is that the CG plays the nodes starting from the top of the rss file.
now the xml looks like this:
<?xml version="1.0" ?>
<rss version="2.0">
<channel>
<title>News</title>
<link>website.com</link>
<description>News</description>
<language>ar-sa</language>
<item>
<title>Headline 1</title>
<description>Headline one the news this hour</description>
</item>
<item>
<title>Headline 2</title>
<description>Fire here flooding over there</description>
</item>
<item>
<title>Headline 3</title>
<description>Fire here flooding over there</description>
</item>
</channel>
</rss>
What i would like todo is have an option to move articles up and down the xml file, so instead of having "Headline 3" third in the list i would like to move it up to be first.
I know with C# you can do this using:
XElement node = ...get the element...
//Move up
if (node.PreviousNode != null) {
node.PreviousNode.AddBeforeSelf(node);
node.Remove();
}
//Move down
if (node.NextNode != null) {
node.NextNode.AddAfterSelf(node);
node.Remove();
Anyone have an idea how i can do this in PHP?
Thanks!
You can have a look at this answer XML reforming with DOM where they use the DOM-parser to rearrange the XML
I would like format the my RSS feed content. Like embed some information with Description tag. I am creating Wordpress Rss feed and trying to create rss 2.0
<?xml version="1.0"?>
<rss version="2.0">
<channel>
<item>
<title>firstquestion</title>
<url>test-domain.com</url>
<description>This is some ifnormation on the description. The below are the answers for the new question</description></item>
</channel>
</rss>
Now, I want to format or further some table or information to be attached with special characters, even html tags formatting in the <description> ... How can I do that?
When I simply insert , it gives me an error?
Use CDATA sections:
$description = '<strong>Strong formatting</strong> or <em>emphasis</em>.';
$item = '<item>
<title>firstquestion</title>
<url>test-domain.com</url>
<description><![CDATA['.$description.']]></description>
</item>';
You can have HTML inside the description element, but you have to encode it using htmlspecialchars.
$description = '<strong>Strong formatting</strong> or <em>emphasis</em>.';
$item = '<item>
<title>firstquestion</title>
<url>test-domain.com</url>
<description>'.htmlspecialchars($description).'</description>
</item>';