2

I have been trying to look into the error but can't seem to solve it. Can anyone help with this. Thank You.

Warning: syntax error, unexpected '(' in D:\langEn.ini on line 4 in D:\Xampp\htdocs\PhpProject1\companyinfo.php on line 12

class CompanyInfo
{
    function parse_files()
    {
        //files created for localization
        $file1 = "D:\langEn.ini";
        $file2 = "D:\jap.ini";

        if($file1 == TRUE)
        {
            print_r(parse_ini_file($file1));
        }
        else
        {
            print_r(parse_ini_file($file2));
        }

    }
}

$obj = new CompanyInfo;
$obj ->parse_files();

Output:

Company Name:
Unikaihatsu Software Private Limited

HO Address(Mumbai):
33-34, Udyog Bhavan, Sonawala Lane,
Goregaon (East), Mumbai, India, PIN 400-063
Phone:+91-22-26867334 Fax:+91-22-26867334
URL: http://www.usindia.com

Branch Office(Ahemdabad):
Unitech Systems 
A/410, Mardia Plaza, Near G. L. S. College,
C. G. Road, Ahmedabad, India, PIN 380-006
Phone:+91-79-26461287 Fax:+91-79-40327081
URL: http://www.usindia.com

Branch Office(Indore):
1st Floor, MPSEDC-STP Building, 
Electronics Complex, 
Pardeshipura, Indore, India, PIN 452010
Phone : +91-731-4075738 Fax : +91-731-4075738
URL : http://www.usindia.com
5
  • Can you show the contents of the D:\langEn.ini file. Commented Jul 4, 2019 at 6:17
  • Company Name: Unikaihatsu Software Private Limited HO Address(Mumbai): 33-34, Udyog Bhavan, Sonawala Lane, Goregaon (East), Mumbai, India, PIN 400-063 Phone:+91-22-26867334 Fax:+91-22-26867334 URL: usindia.com Branch Office(Ahemdabad): Unitech Systems A/410, Mardia Plaza, Near G. L. S. College, C. G. Road, Ahmedabad, India, PIN 380-006 Phone:+91-79-26461287 Fax:+91-79-40327081 URL: usindia.com Commented Jul 4, 2019 at 6:30
  • This is the content that i have in the file Commented Jul 4, 2019 at 6:31
  • 1
    Add the content of the ini file to your question using the "edit" button and format it properly so we can see the different lines etc. In the comments it's harder to read it properly. Thanks Commented Jul 4, 2019 at 6:39
  • Thanks@ADyson. I will surely keep that in mind from now onwards. Commented Jul 4, 2019 at 7:39

1 Answer 1

1

I think the reason for the error is that you cannot use certain characters in your ini file.

In your case entries such as HO Address(Mumbai) are invalid due to the brackets ( and ).

From the PHP Manual:

Characters ?{}|&~![()^" must not be used anywhere in the key and have a special meaning in the value.

You can read more in the parse_ini_file() documentation.


P.S. The above is the cause of the error you've asked about, but it's not the only problem you will encounter.

You should review your file structure in general, because it does not appear to match the standard ini file format at all. An ini file should generally be in the form

[simple]
val_one=SomeValue
val_two=567

[simple2]
val_three=SomeOtherValue
val_four=890

where [simple] denotes a section, and then val_one, val_two etc. are keys, and SomeValue, 567 etc. are values. Parsing the above using PHP's parse_ini_* functions would produce either

Array
(
    [val_one] => SomeValue
    [val_two] => 567
    [val_three] => SomeOtherValue
    [val_four] => 890
)

or

Array
(
    [simple] => Array
        (
            [val_one] => SomeValue
            [val_two] => 567
        )

    [simple2] => Array
        (
            [val_three] => SomeOtherValue
            [val_four] => 890
        )
)

depending on whether the $process_sections flag is set false or true. Live demo: https://3v4l.org/4q82F

Also this is slightly odd data to store in an ini file - these files are normally used to store things like application settings, whereas your office addresses are probably more suited to storing in a database (or at the very least in a JSON file), where there would be a) more structure, and b) fewer restrictions on the use of non-alphanumeric characters.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.