View Full Version : Array as string to test true/false error

01-14-2012, 04:41 PM
Hi all

I am gettting a file and exploding it by '=' to get an array in two parts, 0 and 1. Part 1 is used in a form to show the output.

The problem I have is when I get to a select input, I want the value of 1 for this part of the array.

For some reason, I cant test if it is true or false, I guess this it is not a string?

$file_handle = fopen("saves/server.properties", "rb");

$vars = array();
while (!feof($file_handle) )
$line_of_text = fgets($file_handle);
$parts = explode('=', $line_of_text);

//if date not required
if ( !isset($parts[1]) )
$vars[$parts[0]] = $parts[1];


<form class="clean" method="post">
<legend>Server Properties </legend>
<li style="">
<label for="nether">Allow Nether</label>
<select id="nether" name="nether">
<option <?php if ( $vars['allow-nether'] = "true" ) echo 'selected="selected"'; ?> value="true" >True</option>
<option <?php if ( $vars['allow-nether'] = "false" ) echo 'selected="selected"'; ?> value="false" >False</option>

Anyone help out?

01-14-2012, 05:22 PM
A little confused on what your trying to do here. But if isset isnt working, try to get the length of the array using count($parts) and check to see if the length is > 1. If im missing the problem feel free to let me no.

01-15-2012, 11:44 AM
Isset will not work for this situation, use empty instead.
Also, right from the manual for fgets:

Reading ends when length - 1 bytes have been read, on a newline (which is included in the return value), or on EOF (whichever comes first). If no length is specified, it will keep reading from the stream until it reaches the end of the line.

So you need to trim it first.