The code below works fine, but is way to long! now i have a few of these linked together its taking some time to process and configure each page!
Program requirments;
1. Get source code from web page
2. Dump in txt file
3. delete all but the line i say i want to keep
4. trim out all non numberic chars
5. save / close txt file.
here the code [working];
<?
$mainfile = 'test.txt';
$source = file("http://www.example.com/index.html");
$data = join ($source);
function filterBadWords($str){
$badwords=array( "[a]", "[b]", "[c]", "[d]" , "[e]", "[f]", "[g]", "[h]" , "[i]", "[j]" ,"[k]", "[l]", "[m]", "[n]", "[o]", "[p]", "[q]", "[r]" , "[s]", "[t]" , "[u]", "[v]", "[w]", "[x]", "[y]", "[z]" , "[<]", "[>]" ,"[/]", "[\]" , "[']" , "[%]", "[=]" , "[+]", "[{]", "[}]", "[-]", "[#]", "[&]" , "[*]", "[:]" , "[;]");
$replacements=( "" );
for($i=0;$i < sizeof($badwords);$i++){
srand((double)microtime()*1000000);
$str=eregi_replace($badwords[$i], $rand_key, $str);
}
return $str;
}
$data = filterBadWords($data);
$fp = fopen( $mainfile, "w");
fwrite( $fp, $data );
$filearray=file( $mainfile );
$fp = fopen($mainfile,"w");
$c=count($filearray);
//Added lines to the top - high number mores lines add on to the top
for($i=($c < 76 ? 0 : $c-76);$i < $c;++$i) {
fputs($fp,$filearray[$i]);
}
fclose($fp);
$inp = file($mainfile);
$out = fopen($mainfile,'w');
//lower the number the more content comes through
for ($i=0;$i<count($inp)-73;$i++)
fwrite($out,$inp[$i]);
fclose($out);
?>
there has gotta be a way easy of shorting this down? Hasen`t there? Im just a newbie im affraid been reading about flatfiles for a few days now so i decide to post for help. thanks for reading.