...

View Full Version : Enhancing the Parser Script



ssskaya
03-18-2007, 01:37 AM
Below is a very useful rss parser script that publishes content from two different web sites. The format of the published result is as follows:

e.g.

21 Mar 2007 - Man Bites Dog Again (linked) / The name of the source site
20 Mar 2007 - Another Man Bites Dog (linked) / The name of the source site
19 Mar 2007 - Man Bites Dog (link) / The name of the source site

I want to make a change to the script.

What I want to do is:

I want to associate each of the two sources with a different icon, and I want the script to publish the icon instead of the name of the source site.

How can I do this?

Thanks.



<?
$strip_tags = true;
//set this to true if you are going to constrain the length of the string or if you want to get rid of all html except for links

$allowed_tags = '';//<a>
$constrain_string = true;
$day_limit = 5;
//set this to true if you want the string to be a creatin amount of characters long. $strip_tags must be set to true for this to work.

$string_limit = 400;
$feeds = array();

$feeds[] = array('feed'=>'http://www.site1.com/index.xml','type'=>'rss','name'=>'Name of Site 1', 'href'=>'http://www.site1.com');
$feeds[] = array('feed'=>'http://www.site2.com/index.xml','type'=>'rss','name'=>'Name of Site 2', 'href'=>'http://www.site2.com');

$rss_parser = new dailyTopTen();

$top_ten = array();
$top_ten = $rss_parser->getfeeds($feeds);

$xhtml = '';
$counter = 0;
foreach($top_ten as $_date => $feeds)
{
$counter++;
if($counter<=$day_limit )
{
foreach($feeds as $feed)
{

$xhtml .= '<strong>'.date('j M Y',strtotime($_date)).'</strong> - '.'<a href="'.$feed['LINK'].'">';
$xhtml .= $feed['TITLE'];
$xhtml .= '</a>';
$xhtml .= '<font color="#999999"> / '.$feed['NAME'].'</font><br />';
}
}
}
echo $xhtml;
?>

warlord
03-18-2007, 02:34 AM
Below is a very useful rss parser script that publishes content from two different web sites. The format of the published result is as follows:

e.g.

21 Mar 2007 - Man Bites Dog Again (linked) / The name of the source site
20 Mar 2007 - Another Man Bites Dog (linked) / The name of the source site
19 Mar 2007 - Man Bites Dog (link) / The name of the source site

I want to make a change to the script.

What I want to do is:

I want to associate each of the two sources with a different icon, and I want the script to publish the icon instead of the name of the source site.

How can I do this?

Thanks.



<?
$strip_tags = true;
//set this to true if you are going to constrain the length of the string or if you want to get rid of all html except for links

$allowed_tags = '';//<a>
$constrain_string = true;
$day_limit = 5;
//set this to true if you want the string to be a creatin amount of characters long. $strip_tags must be set to true for this to work.

$string_limit = 400;
$feeds = array();

$feeds[] = array('feed'=>'http://www.site1.com/index.xml','type'=>'rss','name'=>'Name of Site 1', 'href'=>'http://www.site1.com');
$feeds[] = array('feed'=>'http://www.site2.com/index.xml','type'=>'rss','name'=>'Name of Site 2', 'href'=>'http://www.site2.com');

$rss_parser = new dailyTopTen();

$top_ten = array();
$top_ten = $rss_parser->getfeeds($feeds);

$xhtml = '';
$counter = 0;
foreach($top_ten as $_date => $feeds)
{
$counter++;
if($counter<=$day_limit )
{
foreach($feeds as $feed)
{

$xhtml .= '<strong>'.date('j M Y',strtotime($_date)).'</strong> - '.'<a href="'.$feed['LINK'].'">';
$xhtml .= $feed['TITLE'];
$xhtml .= '</a>';
$xhtml .= '<font color="#999999"> / '.$feed['NAME'].'</font><br />';
}
}
}
echo $xhtml;
?>

instead of...


$xhtml .= '<font color="#999999"> / '.$feed['NAME'].'</font><br />';

... you could do something like:


$xhtml .= '<img src="'.$feed['NAME'].'.png"><br />';

Where you would create an icon based on the $feed['NAME'] - (i.e - site1.png). Without seeing the output of $feed['NAME'] I can only give you the basic idea ... if you have an exact example I could probably help you a little better.

ssskaya
03-18-2007, 05:18 AM
Thanks a pretty practical and wise solution!

I cannot see any reason why it would not work!

Thank you!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum