Resend my activation email : Register : Log in 
BCF: Bike Chat Forums


PHP/XML RSS Feed Issue

Reply to topic
Bike Chat Forums Index -> The Geek Zone
View previous topic : View next topic  
Author Message

andrew
Mister Road Rage



Joined: 03 Feb 2002
Karma :

PostPosted: 15:38 - 21 Oct 2008    Post subject: PHP/XML RSS Feed Issue Reply with quote

Hi, i'm making an rss feed at work and am having a few issues with certain validators....

In one validator the feed is showing up as fine, the in another i'm getting this error..

Reference to undefined entity 'eacute'.
Line: 428 Character: 268”

I've attached the PHP code that outputs the RSS feed, i've been told that i need to make sure ALL HTML entities must be referenced as their numeric values.

Could one of you PHP guys take a look and tell me what i need to change/tweak.

Thanks,
Andrew

PHP:
<?php


$DO_BROWSER_SNIFF = false;
$STATIC_PAGE = false;

function htmlentities_to_utf8($text) {
$utf8_entities = array();
$html_entities = array_values(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES));
$entities_decoded = array_keys(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES));

for ($x = 0; $x < sizeof($entities_decoded); $x++) {
$utf8_entities[$x] = '&#' . ord($entities_decoded[$x]) . ';';
}

return str_replace($html_entities, $utf8_entities, $text);
}

function fix_rss($text) {
/* $text = str_replace('&pound;', '£', $text); //ffs */

$text = htmlentities($text);

$text = str_replace('&pound;', '£', $text); //ffs
$text = str_replace('&quot;', '"', $text); //ffs
$text = str_replace('&ouml;', 'ö', $text); //ffs

$text = str_replace('<', '&lt;', $text);
$text = str_replace('>', '&gt;', $text);
# $text = htmlentities_to_utf8($text);

return $text;
}


$WHITESPACE_STRIP = false;
$COMMENTS_STRIP = false;
$DEBUG = false; // Stop debugging info breaking the XML

start_cp('Startup');
start(); init_skin(); $db = init_db();
end_cp();

$SKIN_PATH = '/data/sites/htdocs/rss/';

$tpl = make_template('blah.xml');

$type = $_GET['type'] + 0;
$filter = $_GET['filter'] + 0;
$limit = $_GET['limit'] + 0;
$priority = $_GET['priority'] + 0;
$target = trim($_GET['target']);

$href_self = "url";

if ($target != 'blah') {
die("Invalid target");
}

// Feed codes for HBX

$filter_check = '1';
$add_format = '';

$exclude_filter = str_replace('*', 'exclude_from', make_exclude_filter());
$include_filter = str_replace('*', 'blah', make_include_filter());

$site_name_rss = $CONFIG['site_name_rss'];

$feed_name = 'News';
$feed_title = "{$site_name_rss} - {$add_format}News";
$feed_link = 'https://www.site.com/news.php' . "?cid=OTC-RSS&amp;attr=site-feed-RSS";
$feed_desc = "All the latest {$add_format} {$site_name_rss}";

$active_check = str_replace('*.', '', make_active_check('article'));

$ret = db_query("SELECT /*** Feeds ***/
*,
UNIX_TIMESTAMP(valid_from) AS item_date
FROM
portal.A_articles
WHERE
$type_check AND
valid_from > DATE_SUB(NOW(), INTERVAL 90 DAY) AND
$filter_check AND
$priority_check AND
on_listings = 'yes' AND
$active_check AND
$exclude_filter AND
$include_filter
ORDER BY
running_order DESC
LIMIT
$limit");
if (! $ret->numRows()) {
dlog('Found no suitable articles');
} else {
while ($row = $ret->fetchRow()) {

$aid = $row['id'] + 0;
$link = "https://www.site.com/article.php?id=$aid" . "?cid=OTC-RSS&amp;attr=site-blah-RSS";

$pics = 0;
$ret_pic = db_query("SELECT id FROM portal.A_screenshots WHERE R_article_id = $aid ORDER BY running_order_article ASC, id ASC");
portal.A_screenshots.R_article_id = portal.A_articles.id ORDER BY running_order_product DESC LIMIT 1");

while ($row_pic = $ret_pic->fetchRow()) {
$pid = $row_pic['id'] + 0;
$pics ++;
$pic = "https://medialib.com/screens/screenshot_{$pid}_thumb93.jpg";
$pic_file = "/data/sites/htdocs/medialib/screens/screenshot_{$pid}_thumb93.jpg";
if ($pics == 1) {
$tpl->setCurrentBlock('item.enclosure');
$tpl->setVariable(array(
'item.enclosure.url' => $pic,
'item.enclosure.length' => @filesize($pic_file) + 0,
));
$tpl->parseCurrentBlock();
}
$tpl->setCurrentBlock('item.image');
$tpl->setVariable(array(
'item.image.src' => $pic,
'item.image.link' => $link,
));
$tpl->parseCurrentBlock();
}
if ($pics > 0) {
$tpl->touchBlock('item.images');
}

$headline = trim($row['R_headline']);
$subhead = trim($row['subheadline']);
$description = trim($row['intro_text'] . $row['body_copy']);
if ($subhead) {
if (substr($subhead, -1) != '.') {
$subhead .= '.';
}
$description = '' . $subhead . "<br />\n\n" . $description;
}

switch ($row['R_article_type']) {
case 1:
$category = 'News';
break;
}


$description = preg_replace("/(<!--([^-]*([^-]|-([^-]|-[^>])))*-->)/", '', $description);



$description = nl2br($description); # Covert line breaks to <br />


$tpl->setCurrentBlock('item');
$tpl->setVariable(array(
'item.title' => fix_rss($headline),
'item.description' => fix_rss($description),
'item.link' => $link,
'item.guid' => $link,
'item.category' => fix_rss($category),
'item.date' => str_replace(' ', ' ', date('r', $row['item_date'])),
));
$tpl->parseCurrentBlock();

}
}

header('Content-type: text/xml; charset="utf-8"');

$tpl->setVariable(array(
'rss_href_self' => $href_self,
'rss_title' => fix_rss($feed_title),
'rss_link' => $feed_link,
'rss_description' => fix_rss($feed_desc),
'rss_language' => 'en-gn',
'rss_date' => str_replace(' ', ' ', date('r')),
));

start_cp('Cleanup');
$pagecode = $tpl->get(); finish(); end_cp();


// Super paranoid replacments to make sure NO entities get through
$pagecode = str_replace('&pound;', '£', $pagecode);
$pagecode = str_replace('&quot;', '"', $pagecode);
$pagecode = str_replace('&ouml;', 'ö', $pagecode);

$pagecode = str_replace('&lt;b&gt;', '&lt;strong&gt;', $pagecode);
$pagecode = str_replace('&lt;/b&gt;', '&lt;/strong&gt;', $pagecode);


$pagecode = draw_debug_info($pagecode); output_page($pagecode);

##########################################################

?>
 Back to top
View user's profile Send private message Send e-mail You must be logged in to rate posts

Kickstart
The Oracle



Joined: 04 Feb 2002
Karma :

PostPosted: 16:30 - 21 Oct 2008    Post subject: Reply with quote

Hi

Not sure but suspect that 'eacute' ( é ) isn't valid in the utf-8 characterset.

Looking round the suggestion seems to be to change it to :-

Code:

é


so put:-

Code:

$pagecode = str_replace('& # 2 3 3;', 'é', $pagecode);


in the section at the end (and take the spaces out of & # 2 3 3 ; )

All the best

Keith
____________________
Traxpics, track day and racing photographs - Bimota Forum - Bike performance / thrust graphs for choosing gearing
 Back to top
View user's profile Send private message Send e-mail You must be logged in to rate posts
Old Thread Alert!

The last post was made 17 years, 327 days ago. Instead of replying here, would creating a new thread be more useful?
  Display posts from previous:   
This page may contain affiliate links, which means we may earn a small commission if a visitor clicks through and makes a purchase. By clicking on an affiliate link, you accept that third-party cookies will be set.

Post new topic   Reply to topic    Bike Chat Forums Index -> The Geek Zone All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Read the Terms of Use! - Powered by phpBB © phpBB Group
 

Debug Mode: ON - Server: birks (www) - Page Generation Time: 0.07 Sec - Server Load: 0.91 - MySQL Queries: 13 - Page Size: 40.33 Kb