TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   why is my description limiter not working ? (http://www.talkphp.com/absolute-beginners/3080-why-my-description-limiter-not-working.html)

codefreek 07-07-2008 12:44 PM

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>";



?>


Jim 07-07-2008 01:32 PM

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 :)

codefreek 07-07-2008 02:16 PM

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!


All times are GMT. The time now is 06:22 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0