I want to make a simple script that will write my new internet config for me. The syntax is like this: auto eth1:1 iface eth1:1 inet static address XXX.XXX.XXX.XXX netmask 255.255.255.0 Code (markup): So my code (never tried doing something like this, so I have no idea what to do lol) is this: <?php $ip = file_get_contents('ips.txt'); $eth = file_get_contents('eth.txt'); echo 'auto $eth \n'; echo 'iface inet static \n'; echo 'address $ip'; echo 'netmask 255.255.255.0'; ?> PHP: which obviously will not work. How can I have php make an array out of each line of those two files? The ips.txt contains the IPs I want to use, and the eth.txt contains the interface names, each line by line Thanks!
The file function will read a file and return the contents as an array where each element of the array corresponds to one line in the file.
Plus, variables and new line characters won't be parsed between single quotes. Use double quotes instead.
So would I just make a foreach loop then? I don't know how to set up a loop that will loop all of my text, not just the contents of the file. I can get it so that it echoes the contents of the file, but I only want one line, then I need the whole thing to loop again eg: