Read & Write Entries From the HostsFile with PHP.
You can install the package via composer:
composer require appstract/php-hostsfile
$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
Contributions are welcome, thanks to y'all :)
Appstract is a small team from The Netherlands. We create (open source) tools for webdevelopment and write about related subjects on Medium. You can follow us on Twitter, buy us a beer or support us on Patreon.
The MIT License (MIT). Please see License File for more information.