Jump to content

Output Line in File


verdrm

Recommended Posts

I have a text file and I need to find a specific line and output the contents of the line.

 

Example (in file):

CurrentVersion = 1.2.3.4 

 

I need to get the "1.2.3.4" after CurrentVersion. How can I do that?

 

Thanks!

Link to comment
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
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
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
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
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
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
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
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.