PHP code example of zawadi / gitignore-writer

1. Go to this page and download the library: Download zawadi/gitignore-writer 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/ */

    

zawadi / gitignore-writer example snippets


$gitIgnoreWriter = new \Zawadi\GitignoreWriter\GitignoreWriter(
    './path/.gitignore', # the path of your .gitignore file 
    'name-of-my-section' # the name of the section you want to edit
);
# add items
$gitIgnoreWriter->updateSection(['/robots.txt', '/admin']);

# remove items
$gitIgnoreWriter->updateSection([], ['/robots.txt', '/admin']);

# add and remove items at the same time
$gitIgnoreWriter->updateSection(['/robots.txt', '/admin'], ['to.remove.txt']);

# replace entire section with new items; all existing items will be removed
$gitIgnoreWriter->replaceSection(['/robots.txt', '/admin']);

# remove entire section is the same as replacing it with nothing
$gitIgnoreWriter->replaceSection();

# get list of current entries in a section
$entries = $gitIgnoreWriter->getEntries();