Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2010
    Thanked 0 Times in 0 Posts

    Array as string to test true/false error

    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?

  2. #2
    New Coder
    Join Date
    Jan 2012
    Thanked 6 Times in 6 Posts
    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.

  3. #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Saskatoon, Saskatchewan
    Thanked 2,668 Times in 2,637 Posts
    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.


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts