i need to do a very basic task...

read every line in a log file AND if it finds a string im looking for copy that entire LINE to another file then keep moving

essentially i need to make a minilog file from a master one

whats really hanging me up is how you copy the entire line to another file

    Well, log files can get pretty big, so I wouldn't be wanting to read the whole thing at once in case memory goes pop, so there's your fgets - and now we be needing your criteria for selecting a line - would a simple [man]strpos[/man] find your line, or do you need some more complex regular expression type thing? Sadly I've got to be going to bed, as the merlot-chlorians are strong in my veins, but if I can help in the morning (afternoon) when I get up I will.
    Saluté!

      basically.... i need to feed my script an IP address... and wherever it finds that IP address copy that whole line out to a log file of its own

        You basically need a loop.

        $out_fp = fopen( ... );
        $fp = fopen( ... );
        while( $line = fgets( $fp ,1000 ) ) {
            if( strpos( $line,$ip ) !== FALSE ) {
                fwrite( $out_fp , $line )
            }
        }

          Something like:

          $log = fopen('log_file_name', 'r');
          $newLog = fopen('new_log_file_name', 'w');
          while(!EOF)
          {
             $line = fgets($log);
             if(strpos($line, $ipAddress) !== false)
             {
                fputs($newLog, $line);
             }
          }
          fclose($log);
          fclose($newLog);
          

          Heh, that one minute it took to look up whether it's strpos(needle, haystack) or strpos(haystack, needle) let Halfabee beat me to it. 😉

            thanks to both...

            this did nicely:

            <?php
            $ip = '';
            $out_fp = fopen($ip.'.log','w' );
            $fp = fopen('ex080904.log','r');
            while( $line = fgets( $fp ,1000 ) ) {
                if( strpos( $line,$ip ) !== FALSE ) 
            	{
                    fwrite( $out_fp , $line );
                }
            }
            ?>
            
              Write a Reply...