PHP help needed

iosoft

PC enthusiast since MS DOS 5
Skilled
I need a help on PHP Coding.

The problem is, I want to save some configuration info in a .INI file in this format -

configuration.ini
param1=val1
param2=val2
param3=val3
param4=val4
etc.

How can I easily read/write the value of paramX from this file ?
 
<?php

$file = 'G:\projects\phpinfo.php';

if (file_exists($file) == false) {
die('It doesn\'t exist!');
}

$data = file_get_contents($file);

?>

This will get all the contents from the file. as for easily reading from the data.
You can use explode function to store data in array after every end-line or u can use comma. for e.g

para1 = ans1,
para2 = ans2,

for retrieving this we will have to use
$split = explode(",", $data);
Now $split is an array containing all the params.
$split[0] will be para1 = ans1

for writing

file_put_contents ($file, $data);

Note : file_get_contents() is not useful if you can find out the exact byte where ur params are stored as this will take away the need for exploding.

for writing after specified byte
$F = fopen("myfile.txt","a");

fseek($F, 11);

fwrite($F,"Imran");

fclose($f);

This method will only work if the number of bytes used will remain same in the constant.
 
don't mean to hijack the thread but can someone provide some links to tutorials where i can learn php. planning on working on LAMP setup.
 
Back
Top