PHP code example of appstract / php-hostsfile

1. Go to this page and download the library: Download appstract/php-hostsfile 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/ */

    

appstract / php-hostsfile example snippets


$host = new Appstract\HostsFile\Processor($path); // optional path to the file

$host->getLines(); // get all lines in the hostsfile
$host->addLine($ip, $domain, $aliases); // add a new line to the hostsfile
$host->set($ip, $domain, $aliases); // add a new line and overwrite any existing
$host->removeLine($domain); // remove a line from the hostsfile by domain
$host->save(); // save the changes to the hostsfile
bash
composer