Jump to content

Output Line in File


verdrm

Recommended Posts

The parse_ini_file function doesn't care what the file extension is.

 

Let's say I have a file named "x.x" which contains:

line1
line 2
line 3
CurrentVersion = 1.2.3.4

Using

<?php
$x = parse_ini_file('x.x');
?>

$x contains

Array
(
    [CurrentVersion] => 1.2.3.4
)

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/207727-output-line-in-file/#findComment-1085927
Share on other sites

I tried that against my INF file using the code you provided.

 

When I used a file with test data:

 

[Config]

one = two

 

I could output "two" using $e[one];

 

However, in the actual file I am using, this does not work.

 

[Version]

signature  = "$Windows NT$"

Class      = "ActivityMonitor"

ClassGuid  = {b86dff51-a31e-4bac-b3cf-e8cfe75c9fc2}

Provider    = %Symc%

DriverVer  = 06/24/2009,12.8.0.10

CatalogFile = SymEvent.cat

Link to comment
https://forums.phpfreaks.com/topic/207727-output-line-in-file/#findComment-1085934
Share on other sites

You're getting errors because there are strings containing non alphanumeric characters that are not quoted. If you change your file to contain:


[Version]
signature   = "$Windows NT$"
Class       = "ActivityMonitor"
ClassGuid   = "{b86dff51-a31e-4bac-b3cf-e8cfe75c9fc2}"
Provider    = "%Symc%"
DriverVer   = "06/24/2009,12.8.0.10"
CatalogFile = SymEvent.cat

then the function will work.

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/207727-output-line-in-file/#findComment-1085943
Share on other sites

I used parse_ini_file() on the data you posted and got the expected results -

            [signature] => $Windows NT$
            [Class] => ActivityMonitor
            [ClassGuid] => {b86dff51-a31e-4bac-b3cf-e8cfe75c9fc2}
            [Provider] => %Symc%
            [DriverVer] => 06/24/2009,12.8.0.10
            [CatalogFile] => SymEvent.cat

 

Perhaps if you defined: this does not work?

 

Link to comment
https://forums.phpfreaks.com/topic/207727-output-line-in-file/#findComment-1085958
Share on other sites

I think you want just the contents of the one specific line, right? Easy enough to do; just foreach() loop through the result of parse_ini_file (which is $x) and echo the $key and $value where the $key == your_string.

Link to comment
https://forums.phpfreaks.com/topic/207727-output-line-in-file/#findComment-1085965
Share on other sites

The problem is that I can't get the results to print out.

 

Code:

 

$x = parse_ini_file('file.inf');

print_r($x);

 

This doesn't work.

 

My Data:

 

[Version]

signature  = "$Windows NT$"

Class      = "ActivityMonitor"

ClassGuid  = {b86dff51-a31e-4bac-b3cf-e8cfe75c9fc2}

Provider    = %Symc%

DriverVer  = 06/24/2009,12.8.0.10

CatalogFile = SymEvent.cat

Link to comment
https://forums.phpfreaks.com/topic/207727-output-line-in-file/#findComment-1085972
Share on other sites

My code -

<?php
$x = parse_ini_file('config.inf');
echo "<pre>",print_r($x,true),"</pre>";
?>

 

Are you sure the file is named like you are using in the code and it is not actually - file.inf.txt? Are you developing and debugging your php code on a system with error_reporting set to E_ALL and display_errors set to ON so that all the errors php detects would be reported and displayed?

Link to comment
https://forums.phpfreaks.com/topic/207727-output-line-in-file/#findComment-1085987
Share on other sites

This is interesting, when I use xampp (Windows 7, php 5.3.1), it works perfectly. When I use the PHP CLI on my Linux box (php v5.2.9), I get a error parsing the file. When I move the script & file that work under php 5.3.1 to the linux box and run it I get the error:

Warning: Error parsing config.inf on line 4 in /home/rbnsn/public_html/phpfreaks/test_ini.php on line 2

the file contains

[Version]
signature   = "$Windows NT$"
Class       = "ActivityMonitor"
ClassGuid   = {b86dff51-a31e-4bac-b3cf-e8cfe75c9fc2}
Provider    = %Symc%
DriverVer   = 06/24/2009,12.8.0.10
CatalogFile = SymEvent.cat

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/207727-output-line-in-file/#findComment-1085997
Share on other sites

I managed to get it to work using code on the PHP manual page for the ini parser.

 

Array ( [Version] => Array ( [signature] => $Windows NT$ [Class] => ActivityMonitor [ClassGuid] => {b86dff51-a31e-4bac-b3cf-e8cfe75c9fc2} [Provider] => %Symc% [DriverVer] => 06/24/2009,12.8.0.10 [CatalogFile] => SymEvent.cat )

 

 

The only issue now is how do I extract DriverVer?

Link to comment
https://forums.phpfreaks.com/topic/207727-output-line-in-file/#findComment-1086003
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.