PHP code example of michaelgarrez / text-file

1. Go to this page and download the library: Download michaelgarrez/text-file library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

michaelgarrez / text-file example snippets




$textFile = new TextFile('text_file.txt');



$textFile = new TextFile('text_file.txt');

// Move to a specific line

$textFile->goToLine(5); // This does not return the line content (See Reading).

// Count lines

$count = $textFile->countLines(5);

// Move before a specific character

$textFile->goBeforeCharacter(5); // This does not return the line content (See Reading).



$textFile = new TextFile('text_file.txt');

// Getting lines range

$iterator = $textFile->getLinesRange(0, 5); // Returns an Iterator containing line content from a line to another

$textFile->goToLine(4);

// Getting current line content

$content = $textFile->getCurrentLineContent(); // Returns content of line 4

// Getting next line content

$content = $textFile->getNextLineContent(); // Returns content of line 5

// Getting previous line content

$content = $textFile->getPreviousLineContent(); // Returns content of line 3

// Getting specific line content

$content = $textFile->getLineContent(6); // Returns content of line 6

// Getting next character content

$character = $textFile->getNextCharacterContent(); // Returns next character after pointer position

// Getting previous character content

$character = $textFile->getNextCharacterContent(); // Returns previous character after pointer position

// Getting specific character content

$character = $textFile->getCharacterContent(7); // Returns 7 character from beginning of file
bash
composer install michaelgarrez/text-file