user174372
user174372

Reputation: 17

Parsing INI file with PHP when amperstand (&) in value

I want to parse an ini file. It has alphanumeric values as well as some special characters like (&#-@) etc. But it is not parsing correctly. I have recieved error message {E_WARNING: [/home/php/init/config.php:29] syntax error, unexpected '&' in .conf.ini on line 7}. This is my ini file:

[Main]
DATABASE = test;
USER = root;
PASS = null;
HOST = localhost;
......
Def_Title = Welcome to Oggy & Chocroach.; //line 7
....
"Special & Featured" = "Alry Bee"; //line 17

I want to keep [&] operator in my fille. Any help may appreciated.

Upvotes: 0

Views: 96

Answers (1)

Barmar
Barmar

Reputation: 781726

From the documentation:

Note:
If a value in the ini file contains any non-alphanumeric characters it needs to be enclosed in double-quotes (").

So the line should be:

Def_Title = "Welcome to Oggy & Chocroach."

You can't have & in the keys, only the values.

Upvotes: 1

Related Questions