jege Posted July 12, 2012 Share Posted July 12, 2012 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. Quote Link to comment Share on other sites More sharing options...
Barand Posted July 12, 2012 Share Posted July 12, 2012 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 ) Quote Link to comment Share on other sites More sharing options...
jege Posted July 12, 2012 Author Share Posted July 12, 2012 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) Quote Link to comment Share on other sites More sharing options...
Barand Posted July 12, 2012 Share Posted July 12, 2012 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. Quote Link to comment Share on other sites More sharing options...
jege Posted July 12, 2012 Author Share Posted July 12, 2012 Yea, it did work 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.