Jump to content

Baruti

New Members
  • Content count

    2
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Baruti

  • Rank
    Newbie
  1. Baruti

    Delete HOST from CONF file with PHP

    it work like a charm, thank you
  2. Hello, can anyone have idea how to delete HOST from conf file, dhe conf file is a txt format i have dhcpd conf file is like this # interface eth0 subnet 10.0.10.0 netmask 255.255.255.0 { } host cm-test1 { hardware ethernet 78:8d:f7:2b:bc:79; fixed-address 172.17.12.80; filename "srv-050.cfg"; } host cm-test2 { hardware ethernet 5c:35:3b:4d:73:4b; fixed-address 172.17.13.119; filename "srv-042.cfg"; } and i want to delete only hosts host cm-instrumenti { hardware ethernet 78:8d:f7:2b:bc:79; fixed-address 172.17.12.80; filename "srv-050.cfg"; } host cm-nimonmehmetaj { hardware ethernet 5c:35:3b:4d:73:4b; fixed-address 172.17.13.119; filename "srv-042.cfg"; } i have tried with this function function deleteLineInFile($file,$string) { $i=0;$array=array(); $read = fopen($file, "r") or die("can't open the file"); while(!feof($read)) { $array[$i] = fgets($read); ++$i; } fclose($read); $write = fopen($file, "w") or die("can't open the file"); foreach($array as $a) { if(!strstr($a,$string)) fwrite($write,$a); } fclose($write); } echo deleteLineInFile("dhcpd.conf","host cm-test1"); and deletet this line host cm-test1 { I can delete row per row with this function, but i think is not a god way thanks for your help
  3. Baruti

    Hello

    I am new here, i am 25 years old, and i am starting learn php.
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.