Utilities
|
|
|
|
<? /* -----------------------------------
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
|
|
|
|