src/Handlers/GenericFileHandler.php
/**
     * Remove's the passed line from the file with the passed file handle.
     *
     * @param string   $line The line to be removed
     * @param resource $fh   The file handle of the file the line has to be removed
     *
     * @return void
     * @throws \TechDivision\Import\Exceptions\LineNotFoundException Is thrown, if the requested line can not be found in the file
     * @throws \Exception Is thrown, if the file can not be written, after the line has been removed
     */
Remove's the passed line from the file with the passed file handle.
@param string   $line The line to be removed
@param resource $fh   The file handle of the file the line has to be removed


Remove ' s the passed line from the file with the passed file handle . @param string $line The line to be removed @param resource $fh The file handle of the file the line has to be removed
public function removeLineFromFile(string $line, $fh) : void
    {
        $lines = array();
        $found = false;
        rewind($fh);
        while (($buffer = fgets($fh, 4096)) !== false) {
            $buffer = trim($buffer);
            if ($line === $buffer) {
                $found = true;
                continue;
            }
            $lines[] = $buffer;
        }
        if ($found === false) {
            throw new LineNotFoundException(sprintf('Line "%s" can not be found', $line));
        }
        ftruncate($fh, 0);
        rewind($fh);
        foreach ($lines as $ln) {
            if (fwrite($fh, $ln . PHP_EOL) === false) {
                throw new \Exception(sprintf('Can\'t write "%s" to file', $ln));
            }
        }
        clearstatcache();
    }
public function removeLineFromFile ( string $ line , $ fh ) : void { $ lines = array ( ) ; $ found = false ; rewind ( $ fh ) ; while ( ( $ buffer = fgets ( $ fh , 4096 ) ) !== false ) { $ buffer = trim ( $ buffer ) ; if ( $ line === $ buffer ) { $ found = true ; continue ; } $ lines [ ] = $ buffer ; } if ( $ found === false ) { throw new LineNotFoundException ( sprintf ( 'Line "%s" can not be found' , $ line ) ) ; } ftruncate ( $ fh , 0 ) ; rewind ( $ fh ) ; foreach ( $ lines as $ ln ) { if ( fwrite ( $ fh , $ ln . PHP_EOL ) === false ) { throw new \ Exception ( sprintf ( 'Can\'t write "%s" to file' , $ ln ) ) ; } } clearstatcache ( ) ; }
Remove's the passed line from the file with the passed file handle.
Remove ' s the passed line from the file with the passed file handle .
// initialize the array for the PIDs found in the PID file // initialize the flag if the line has been found // rewind the file pointer // read the lines with the PIDs from the PID file // remove the new line // if the line is the one to be removed, ignore the line // add the found PID to the array // query whether or not, we found the line // empty the file and rewind the file pointer // append the existing lines to the file // clear the file status cache