Exclude hyperlink with exclamation marks in php.ini
I have a config file that accepts text warnings like:
warnings.1 = Please check the date
They are presented to the user as HTML. I need to embed a hyperlink like below:
warnings.1 = <a href="http://foo.com/!FOO!/">check with foo</a>
I can't for the life of me figure out how to avoid this, so that parse_ini_file () can read it and get that line the way I want.
a source to share
http://php.net/manual/en/function.parse-ini-file.php :
array parse_ini_file(string $filename [, bool $process_sections = false [, int $scanner_mode = INI_SCANNER_NORMAL]])
scanner_mode:
It can be either INI_SCANNER_NORMAL (default) or INI_SCANNER_RAW. If INI_SCANNER_RAW is enabled, parameter values โโwill not be parsed.
Changelog: 5.3.0 Added optional scanner_mode parameter.
So you're screwed if you're not into 5.3. Or you need to use a different implementation, parse_ini_file is not the only INI file parser for PHP.
a source to share
I recently ran into some similar scenario and after some thought I came to the conclusion that the problem is not with the function or class being used, but with the usage itself. Parameter values โโsuch as
<a href="http://foo.com/!FOO!/">check with foo</a>
would be better implemented in such a way that the value href
is only the value of the parameter. Example:
warnings.1.href = "http://foo.com/!FOO!/"
warnings.1.text = "check with foo"
This is because parameter values โโshould only contain values โโthat can change (from instance to instance). In your case, the anchor labels are best left in the html itself rather than in the config file .ini
. This not only makes your config file lighter, but also keeps it clean due to the separation of gigs where the HTML should be in HTML and the config values โโin the config file.
So, there is no need to switch PHP versions or add parameters to the function parse_ini_file
(as this would hack the Zend_Config_Ini class, which would be better done as an official patch if needed).
a source to share