Help with get function

Hello,
Today i need php help,
how i can read something by file
Ex.

File.php or file.ini or file.sav
It looks like this:
time=10min
gang=1
ip=IP adreass
bank=323232
money=23232

From this file i want get something after “=”

ex. $GetPlayerInfo[‘gang’] and it gets “1”
ex. $GetPlayerInfo[‘bank’] and it gets “1”

Thanks, :slight_smile:

Well, if it is not a huge text file, you can read it into an array. Each line would be a different entry in the array.
Then, loop thru each array entry and parse each line. You can separate the values by splitting values in each
line into “key” and “value” and then use the results. To do this, you would use the “explode” command.
Not too hard to do.
Something like: $parms=explode("=",$line) which would put left of “=” into $parms[0] and the stuff on the right side of “=” into $parms[1] … Where $line is the full line you got from the file!

You could do this in just a few lines…
1) read entire file into a variable
2) parse the entire file into an array of lines (Hint: use explode and explode on $VBCRLF)
3) loop thru and parse each line into your array of data

Hope all that makes sense! Good luck…

Thanks, i will try, if i have more questions or problems i will post here :slight_smile: , thanks again

try like this

[php]

$input = fopen(‘file.txt’,‘r’);
$array = Array();

while(!feof($input)) {

$line = trim(fgets($input));
$pieces = explode(’=’,$line);
$array[$pieces[0]] = $pieces[1];

}
[/php]

then you have array with key => value

try
print_r($array)
and take a look…

Yes, Sero, I told him that, but, was letting him figure out his own version of the code.
This site has a large number of students looking to finish their homework with.

yes yes, first reply helped me a lot, and the problem is solved, also thanks for other replies :), Administrator can lock this post

Once a member states his problem is solved, he can solve it if he is a regular member or higher.
Otherwise, we can mark it solved as I will do.

We do not “LOCK” posts in case a better solution is found in the future and can be posted.
“Locking” is for posts that we do not want to posted to due to inappropriate content or other reasons.

Yours is solved… Thanks!

ok i dont knew

Sponsor our Newsletter | Privacy Policy | Terms of Service