Zend - The PHP Company




Utilities

Add Code


HOLLYWOOD TOP TEN  

Type: application
Added by: npguy2001
Entered: 08/07/2001
Last modified: 07/12/2000
Rating: - (fewer than 3 votes)
Views: 6093
Extract Hollywood Box Office Results from http://www.hollywood.com and output to file! An excellent example of regular expression using array.


<? 
/* -----------------------------------
   Purpose:
   Regular Expression Example.
   
   This Example grabs the 
   http://www.hollywood.com/movies page TOP TEN list movies and output
   to .htm file. 
     
   Example by: npguy@my-deja.com
   npguy is a Python, PHP and Perl lover. done several utilities in C/C++.
   he lives in butwal, nepal.    
   --------------------------------------- */   
 
/*--- URL to extract the information. ---*/
$url "http://www.hollywood.com";  
$output"hollywood.htm";    
/*Array contain the different regular expression later 
replaced by according to $replace array. 
*/
$search = array ("'<script[^>]*?>.*?</script>'si",  // Strip out javascript..just for security
                 
"'Weekend'",
                 
"'#000066'",  //Border colour 
                 
"'<a href[^>]*?>'si",  // Strip <a href>
                 
"'<a*?>'si",  // </a> tag                 
                 
"'([rn])[s]+'"  // Strip out white space
                 
);  

$replace = array ("",
          
"Hollywood",
          
"'#003366'",
                  
"",
                  
"",
                  
"\1");

/*--- Join array elements with a string..i did with n ---*/
    
$string implode("n"file($url)); 

/*-- Some unique starting text or tag to grab the text --*/
    
$string1 explode("<!--//    box office winners    -->"$string); 
/*-- Some unique ending text or tag to end grabbing --*/
    
$string2 explode("<!--//    special offers    -->"$string1[1]); 
   
    
//$ttt=$string2[0];

    
$final_text preg_replace ($search$replace$string2[0]);
    
    
$buffer="<!-- Start of Top 10 hollywood  -->";
    
$buffer.="<br><center>";
    
$buffer.= $final_text;
    
$buffer.="<!-- End of Top 10 hollywood  -->";
    
$buffer.="</center>";
    
    
$fp fopen ("$output""w");
    if(!
$fp){
    echo 
"Error while generating...$output ";
    die;
    }
    
fwrite($fp,$buffer);
    
fclose($fp);   
       
?> 


Usage Example




Rate This Script





Search



This Category All Categories