Jump to content

Explode help


jege

Recommended Posts

Hey.

I got a file like this:

#A Comment

#And another comment

level=My Level

name=The servers name!

world=world1

flying=false

 

The file is like that but there is around 20 more settings. How could I make that the script gets the contents after = I tried with explode and using = but it always gave the second line until =.

Any ideas. Also, I want to insert the data to an textarea (This I can do myself when I get the values somehow)

Thanks.

Link to comment
Share on other sites

With minor reformatting, you have an ini file format eg

 

;A Comment

;And another comment

level="My Level"

name="The servers name!"

world=world1

flying="false"

 

So you could use parse_ini_file()

 

<?php
$data = parse_ini_file('mytest.txt');

echo '<pre>'.print_r($data, 1).'</pre>';
?>

 

which gives-->

 

Array

(

    [level] => My Level

    [name] => The servers name!

    [world] => world1

    [flying] => false

)

 

 

Link to comment
Share on other sites

Works like a charm, only problem. The file has true and false values.

It ignores all false values and doesn't print them and converts true to 1.

edit: the file doesn't work when I add the "" (The software can't read it anymore)

 

Link to comment
Share on other sites

False will convert to an empty string '', and true to '1'. These will evaluate to false and true if you use if()

 

Alternatively, put "" around the true and false values in the file and you will get the string values "true" and "false"

 

edit: my test file uses "s and that worked. Try substituting 0 and 1 for false/true.

Link to comment
Share on other sites

Yea, it did work :D It just gave a error on another plug-in.

Anyway, my next problem is. How could I save it to the file again? I took all of the data, inserted them to like 10 textfields and then "true / false" values to a dropdown, any tipa?

Should I just use fopen / fsave w/e and other similar functions?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.