Zend - The PHP Company




Miscellaneous

Add Code


freshmeat.net latest news grabbing tools  

Type: application
Added by: simbolon
Entered: 10/04/2001
Last modified: 04/12/2000
Rating: - (fewer than 3 votes)
Views: 5594
grab latest news at freshmeat.net, and attach to your web page.


    
 <?php 
    
/*    latest_news.php
     *    author : Nasir Simbolon <nasir@3wsi.com>,
     *                <http://debian.3wsi.net>     
     *
     *     From The cave 16th Floor, WTC Building
     *      Jl. Jend Sudirman, Jakarta, Indonesia
     */                
   /*-------------------------------------------------
    grap the latest news at freshmeat.net and show it in your web page
   ---------------------------------------------------*/

         //try to connect to  freshmeat.net 
          
if(!$fp=fopen(" http://freshmeat.net" ," r" )) { 
                     echo 
" can not open http://freshmeat.net" 

            } 
            else  {    
                     
// read content 
          
while(!feof($fp)) 
                      
$content.=fgets($fp,1024); 

         
//close  connection     
                      
fclose($fp); 

                      
//cut the top of page  
                      
$content=ereg_replace(" ^.+<!-- static.h --> " ," " ,$content); 

                      
//now get all news by  explode content by <p>  
                      
$news=explode(" <p> " ,$content); 

                      
//take latest news 
                      
$show=" <p> $news[1]<p> $news[2]

                      
//strip <img> 
                      
$show=strip_tags($show," <a> ,<p> ,<b> ,<br> ,<span> " ); 

                      
//add freshmeat.net to href
                      
$show=ereg_replace(" href=" " ," href=" http://freshmeat.net" ,$show); 

                      
//now echo the latest news 
                      
echo $show
    }

  
?> 


Usage Example


See the example


Rate This Script





Search



This Category All Categories