Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Escape illegal chars in .ini-files

Tags:

php

ini

The documentation on parse_ini_file states that you can't use these chars {}|&~![()^" in the value. Is there some way to escape these chars? I need to use them. Normal escaping with \ doesn't seem to work.

like image 613
Martin Avatar asked Mar 29 '10 10:03

Martin


People also ask

How do I escape characters in PHP?

In PHP, an escape sequence starts with a backslash \ . Escape sequences apply to double-quoted strings. A single-quoted string only uses the escape sequences for a single quote or a backslash.

What is escaping special characters in PHP?

Character Escaping Because PHP interprets and interpolates special characters inside double-quoted string literals and heredoc string literals, the backslash sign ( \ ) is used as an "escape character". For example, using \$name instead of $name prevents PHP from interpolating the $name variable.

What is the meaning of \r escape sequence in PHP?

To specify a literal backslash, double it ( \\ ). All other instances of backslash will be treated as a literal backslash: this means that the other escape sequences you might be used to, such as \r or \n , will be output literally as specified rather than having any special meaning.

Which escape character is used for identifying a whitespace character?

Learn More. In Python strings, the backslash "\" is a special character, also called the "escape" character. It is used in representing certain whitespace characters: "\t" is a tab, "\n" is a newline, and "\r" is a carriage return.


2 Answers

The manual says those characters can not be used in the key -- the opposite of the value. To use them in values, double-quote the string.

like image 141
Amy B Avatar answered Oct 22 '22 15:10

Amy B


Try using INI_SCANNER_RAW (from the same documentation) for scanner_mode:

parse_ini_file ( $filename, true, INI_SCANNER_RAW );
like image 29
VadimBelov Avatar answered Oct 22 '22 15:10

VadimBelov