Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Enhancing the Parser Script

    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.


    Code:
    <?
    $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;
    ?>

  • #2
    New Coder
    Join Date
    Feb 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ssskaya View Post
    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.


    Code:
    <?
    $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...

    PHP Code:
    $xhtml .= '<font color="#999999"> / '.$feed['NAME'].'</font><br />'
    ... you could do something like:

    PHP Code:
    $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.

  • #3
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks a pretty practical and wise solution!

    I cannot see any reason why it would not work!

    Thank you!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •