Page 1 of 1

writing to an array into a php file

Posted: Wed Dec 28, 2011 12:44 pm
by dmallia
So i did a game servers listing script and have a file servers.php with 2 arrays in it

Code: Select all

$servers = array('1' => 'ip','2' => 'ip','3' => 'ip',);
$ports = array('1' => 'port','2' => 'port','3' => 'port',);
I would like a script to insert data into that arrays in the file servers.php and save it. I know that there is the fwrite() but don't know if it writes to a php file. I already did the form.

Code: Select all

<form method="post" enctype="multipart/form-data">
<table>
<tr>
	<td align="center"><label>IP</label></td>
    <td align="center"><label>Port</label></td>
    <td></td>
</tr>
<tr>
	<td><input type="text" name ="IP"></td>
    <td><input type="text" name="Port"></td>
    <td><input type="submit" name ="Add"value="Add"></td>
</tr>
</table>
</form>

Re: writing to an array into a php file

Posted: Wed Dec 28, 2011 1:55 pm
by s.dot
I'm not quite sure what you're trying to do.

Have a look at the serialize() and unserialize() functions for storing arrays as strings.

http://www.php.net/serialize
http://www.php.net/unserialize

Re: writing to an array into a php file

Posted: Thu Dec 29, 2011 11:06 am
by dmallia
i have 2 arrays with data in them in servers.php.

Code: Select all

$server = array (
                         '1' => 'ip',
                         '2' => 'ip',
                         '3' => 'ip',);
$port = array (
                     '1' => '28960',
                     '2' => '28961',
                     '3' => '28970',
                      );
I need a script that has to take the ip and port from the text boxes and automatically adds this data to the file server.php and the file becomes as shown below.

Code: Select all

$server = array (
                         '1' => 'ip',
                         '2' => 'ip',
                         '3' => 'ip',
                         '4' => 'ip',
                          );
$port = array (
                     '1' => '28960',
                     '2' => '28961',
                     '3' => '28970',
                     '4' => '28910',
                      );