#native_company# #native_desc#
#native_cta#

freshmeat.net news grapper

By Nasir Simbolon
on April 5, 2001

Version: 1.0

Type: Full Script

Category: Other

License: GNU General Public License

Description: this snippet open connection to http://freshmeat.net, read the content and grap the latest news.
You can see this working in http://debian.3wsi.net/news at the bottom of the page

<?php 
 	/*
	 *	Author : Nasir Simbolon <[email protected]>
	 *	freshmeat.net news grapper 1.0	
	 *	grapper of latest news at freshmeat.net version 1.0
	 */
 
  //open freshmeat.net 
  if(!$fp=fopen(" http://freshmeat.net" ," r" )) { 
 	 echo " can not open http://freshmeat.net" ; 
         exit 
   } 
   
  // read content	
	
   while(!feof($fp)) 
        $content.=fgets($fp,1024); 
   fclose($fp); 

   //cut top of page 
   $content=ereg_replace(" ^.+<!-- static.h --> " ," " ,$content); 
  
  //now do explode content by <p> to get all news 
    $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); 

  //show 
  echo $show; 
?>