Reading INI files with PHP
Another easy tutorial, but it can be useful to store information outside of a MySQL database!
First up, let's make the ini file:
[SOMETHINGHERE]
makesure=1
youinclude=23
thebrakets=345
[SOMETHINGELSE]
YES=12
Alright, you MUST save that as a .ini file. Now for the PHP.
<?php
$arr=parse_ini_file("Yourfile.INI",true);
echo $arr['SOMETHINGHERE']['youinclude']; // echos 23
echo $arr['SOMETHINGELSE']['YES']; // echos 12
?>
Just edit your .ini file as well as your .php file. Here is a full example:
Mystats.ini:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[HP]
AddPerLevel=140
AddPerStr=10
AddPerDef=0
AddPerMagi=0
AddPerSpeed=0
[MP]
AddPerLevel=220
AddPerStr=0
AddPerDef=0
AddPerMagi=10
AddPerSpeed=0
[SP]
AddPerLevel=330
AddPerStr=0
AddPerDef=0
AddPerMagi=0
AddPerSpeed=20
Now, I want to get AddPerLevel under MP.
<?php
$arr=parse_ini_file("mystats.INI",true);
echo $arr['MP']['AddPerLevel']; // echos 220
?>
It's a pretty simple tutorial, enjoy!