TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 07-07-2008, 12:44 PM   #1 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Application Error why is my description limiter not working ?

PHP Code:
<?php

//only use when needed!
//ini_set("user_agent","Internet Explorer");

//Edit here for your rss link
$location "http://youtube.com/rss/global/top_rated.rss";

$contents file_get_contents($location);
$xml        = new SimpleXMLElement($contents);
$limiter 0;
$deslimit $item->description 0;

print 
"<ol>";

foreach(
$xml->channel->item as $item) {
    print 
"<li>";
print 
"<a href='".$item->link."' title='".$item->title."'>";
print 
$item->title;
print 
"</a>";
print 
"<p>".$item->description."</p>";
print 
"</li>";
$limiter++;
if (
$limiter == 5) break;
$deslimit++;
if (
$deslimit == 100) break;

}

print 
"</ol>";



?>

Last edited by codefreek : 07-07-2008 at 01:05 PM. Reason: Code edit!
codefreek is offline  
Reply With Quote
Old 07-07-2008, 01:32 PM   #2 (permalink)
Jim
The Addict
 
Jim's Avatar
 
Join Date: Nov 2007
Location: the Netherlands
Posts: 281
Thanks: 2
Jim is on a distinguished road
Default

With Noia from #talkPHP:

PHP Code:

<?php 

//only use when needed! 
//ini_set("user_agent","Internet Explorer"); 

//Edit here for your rss link 
$location "http://youtube.com/rss/global/top_rated.rss"

$contents file_get_contents($location); 
$xml        = new SimpleXMLElement($contents); 
$deslimit 100;

print 
"<ol>"

// Loop results
foreach($xml->channel->item as $item) { 
    
    print 
"<li>"
    
    print 
"<a href='".$item->link."' title='".$item->title."'>"
    print 
$item->title
    print 
"</a>"
    
    
// Edit description to length
    
if(strlen($item->description) > $deslimit) {
        
$item->description trim(substr($item->description), 0$deslimit) . '...';        
    }
    
    print 
"<p>".$item->description."</p>"
    print 
"</li>"



print 
"</ol>";
Not tested, but should work :)
__________________
Nunchaku! Who doesn't like martial arts? =)
Send a message via MSN to Jim Send a message via Skype™ to Jim
Jim is offline  
Reply With Quote
Old 07-07-2008, 02:16 PM   #3 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Application Error This is the code by Noia and still the image is buging!

PHP Code:
<?php

////////////////////////////////////////////////////////////
// DECLARE CONFIGURATION HERE

//only use when needed!
//ini_set("user_agent","Internet Explorer");


//Edit here for your rss link
$location "http://youtube.com/rss/global/top_rated.rss";

$limit 0// use 0 for no limit
$desclimit 120// use 0 for no limit



//////////////////////////////////////////////////////////
// DECLARE FUNCTION HERE

function fetchRSSFeed($location,$limit 0$desclimit 0) {

    
$contents file_get_contents($location);
    
$xml      = new SimpleXMLElement($contents);
//        var_dump($xml);
    
$desclimit = ($desclimit != && $desclimit $desclimit +$desclimit); // Sanity check
    
$i     0;
    
$str     "";

    
$str .= "<ol>";

    foreach(
$xml->channel->item as $item) {
            
            
//$img = preg_replace('/^.*?(<img [^>]+>).*$/is','\1',$item->description); // Uncomment if you need full <img /> tag
            
$imgsrc preg_replace('/^.*?(<img [^>]*?src="([^"]+)"[^>]*>).*$/is','\2',$item->description);
            
$tmp_desc preg_replace('#.*?(<p>.+?</p>).*#is','\1',$item->description);
            
$tmp_desc trim(preg_replace('#(<[^>]+>|http://\S+|www\.\S+\.\S{2,3}\S+)#','',$tmp_desc));
            
        
$str .= "<li>";
        
$str .= "<a href='".$item->link."' title='".$item->title."'>";
        
$str .= $item->title;
        
$str .= "</a>";
                
$str .= $imgsrc;
        
$str .= "<p>". ((($desclimit != 0) && (strlen($tmp_desc) > $desclimit)) ? substr($tmp_desc,0,$desclimit-3)."..." $tmp_desc) ."</p>";
        
$str .= "</li>";
        if (
$limit != && $i == $limit)
        break;
    }
    
$str .= "</ol>";

    return 
$str;

}

////////////////////////////////////////////////////////////
// USE FUNCTION

print fetchRSSFeed($location,$limit,$desclimit);

// THE END

?>
WORKING!

Last edited by codefreek : 07-07-2008 at 02:32 PM. Reason: CODE WORKING NOW!
codefreek is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 08:30 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design