Jump to content

Need Some Help With Parse_Ini_File


Dutch

Recommended Posts

Hello,

 

I'm having some trouble with parse_ini_file... Let me start off with saying that I have none/very little experience with PHP, but I'm trying to learn. Also, I have looked around on the internet and not even that could help me. :tease-01:

 

Anyway, the thing I want to achieve is:

 

There's an .ini file of which the contents I want outputted into a page on my website.

 

The .ini file is called status.ini, and has these dynamic values inside:

 


[1]
Status=none
Players=0/8
Nominated=Position 1 undecided - Position 2 undecided - Position 3 undecided

[2]
Status=CTF
Players=7/8
Nominated=Position 1 map1 - Position 2 map2 - Position 3 undecided

 

I want that to display on my webpage something like:

 

(Server 1:) Status: none - Players: 0/8 - Nominated: undecided - undecided - undecided

(Server 2:) Status: CTF - Players: 7/8 - Nominated: map1 - map2 - undecided

 

Can someone tell me how to achieve this? Or hint me into the right direction?

Link to comment
Share on other sites

// The name and path of our configuration file

$file="status.ini" ;

// Lets check if the file exists and is readable by our script

if (file_exists($file) && is_readable($file))

{

//yay... the file is readable and exists

//lets parse it into an array

$status=parse_ini_file($file);

//At this point, all the data from the ini file is

//stored in the $settings array... just for the sake of

//convenience you can print it out using

//print_r($settings);

//assign different values from the file to different variables

$status=$status["status"];

$players=$status["players"];

$nominated=$status["nominated"];

 

//echo it! or use it in any other way you wish

echo "$status $players $nominated";

}

else

{

// If the configuration file does not exist or is not readable, DIE php DIE!

die("Sorry, the $file file doesnt seem to exist or is not readable!");

}

 

 

Then it gives me this error:

 

Sorry, the status.ini file doesnt seem to exist or is not readable!

Edited by Dutch
Link to comment
Share on other sites

Still getting the same error...

 

Sorry, the status.ini file doesnt seem to exist or is not readable! :(

 

 

// The name and path of our configuration file
$file="status.ini" ;
// Lets check if the file exists and is readable by our script
if (file_exists($file) && is_readable($file))
{
//yay... the file is readable and exists
//lets parse it into an array
$status=parse_ini_file($file, true);
//At this point, all the data from the ini file is
//stored in the $settings array... just for the sake of
//convenience you can print it out using
//print_r($settings);
//assign different values from the file to different variables
$status=$status["status"];
$players=$status["players"];
$nominated=$status["nominated"];

//echo it! or use it in any other way you wish
echo '<pre>', print_r($status, 1), '</pre>';
}
else
{
// If the configuration file does not exist or is not readable, DIE php DIE!
die("Sorry, the $file file doesnt seem to exist or is not readable!");
}

 

Is what I currently have...

Edited by Dutch
Link to comment
Share on other sites

Well, you certainly took that advice ::)

 

Well, I tried, but got a Template Parse Error on line 177.

 

 

175: // Lets check if the file exists and is readable by our script

176: if (file_exists($file)

177: if (is_readable($file))

178: {

 

I'll assume I'm doing it wrong though. :P

Edited by Dutch
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.