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
https://forums.phpfreaks.com/topic/265562-explode-help/
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
https://forums.phpfreaks.com/topic/265562-explode-help/#findComment-1361036
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
https://forums.phpfreaks.com/topic/265562-explode-help/#findComment-1361042
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
https://forums.phpfreaks.com/topic/265562-explode-help/#findComment-1361094
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.