Reading INI files with PHP - RMB Scripting
You appear not have have an account with us, Click HERE to register an account...
RMB Scripting
Navigation
  Home
  Contact
  FAQ
  Forum
  Topsites
  Members
  Competitions
  Affiliates
Downloads
  Templates
  Scripts
  Fonts
  Image Sets
  Software
  Other
 
Tutorials
  .htaccess
  Photoshop
  C/C++
  CSS
  Macromedia Flash
  MySQL
  PHP
  PHP - User System
  HTML
  Javascript
  Macintosh
  Macromedia Fireworks
  Visual Basic
  Visual C#
  Windows
  Other
 
Latest Tutorials
PHP Roll Dice
Liveprinter For Mac
Scrollbar Coloring
Connect to a MySQL Server
Enabling Windows Dream...
Latest Comments
User System (Part 1)
User System (Part 1)
User System (Part 1)
Limit username restric...
Whos Online
Stats
Total Members: 468 [153]
Total Tutorials: 242
Newsest User: Lauraa
Todays Unique Hits: 14
Users Online: 3
DanielXP, jambomb, setsukemizuhara
4 Guests
Poll
Do you like this poll?
Yes
Maybe
No
Main Content
Tutorial: Reading INI files with PHP By Diablosblizz
Another easy tutorial, but it can be useful to store information outside of a MySQL database!

First up, let's make the ini file:

   
CODE:

[SOMETHINGHERE]
makesure=1
youinclude=23
thebrakets=345
[SOMETHINGELSE]
YES=12


Alright, you MUST save that as a .ini file. Now for the PHP.

   
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:

   
CODE:

[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:
<?php
$arr
=parse_ini_file("mystats.INI",true);
echo 
$arr['MP']['AddPerLevel']; // echos 220
?>


It's a pretty simple tutorial, enjoy!
Difficulty: Easy
Views: 1845
Rating:
Comments
Posted on Sunday 30th December 2007 at 09:00 PM
zerocool
nice tut, but i have a little question.

In PHP i can insert values on this ini files?
Posted on Sunday 30th December 2007 at 10:00 PM
MOD-Shadow
try looking here :) i think i saw a function/class that has a write function.

http://us2.php.net/parse_ini_file
Posted on Monday 31st December 2007 at 02:07 PM
Dean
good tutorial.
Posted on Monday 31st December 2007 at 04:37 PM
Diablosblizz
Zerocool, you could use the fopen function.
Posted on Monday 31st December 2007 at 06:44 PM
MOD-Shadow
if you use fopen it'll open the whole file, though you could most likely use file(); then check which line contains the content you want to edit.
Posted on Tuesday 1st January 2008 at 02:53 AM
Diablosblizz
That's true as well.
Posted on Wednesday 5th March 2008 at 03:41 AM
MOD-Shadow
Also, my random outcome i got bored with

http://hrwp.zapto.org:6020/demo/index.php
Notice:
Remember to post long codes on our pastbin! - (http://rmb.pastebin.com/)
Add Comment
You must be logged in to post a comment.
Good Morning Guest
Username: 
Password: 
Remember Username
Links
RMB Arcade
GangstaMania
Free Domains
Free Games
Alien Design Toplist
Affiliates