Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-14-2012, 03:41 PM   PM User | #1
herghost
New to the CF scene

 
Join Date: Sep 2010
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
herghost is an unknown quantity at this point
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?

Code:
$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]) )
   {
      continue;
   }
   $vars[$parts[0]] = $parts[1];
 

}








?>
<form class="clean" method="post">
        <ol>
          <li>
            <fieldset>
              <legend>Server Properties </legend>
              <ol>
                <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>
                  </select>
Anyone help out?
herghost is offline   Reply With Quote
Old 01-14-2012, 04:22 PM   PM User | #2
12k
New Coder

 
Join Date: Jan 2012
Posts: 29
Thanks: 0
Thanked 6 Times in 6 Posts
12k is an unknown quantity at this point
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.
12k is offline   Reply With Quote
Old 01-15-2012, 10:44 AM   PM User | #3
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,645
Thanks: 4
Thanked 2,450 Times in 2,419 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Isset will not work for this situation, use empty instead.
Also, right from the manual for fgets:
Quote:
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.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Tags
array, string, true/false

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:53 AM.


Advertisement
Log in to turn off these ads.