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.

+2


a source to share


4 answers


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.

+1


a source


Try using urlencode , exclamation marks should be escaped as such:

urlencode("foo.com/!FOO!/");

      



Output:

foo.com%2F%21FOO%21%2F

      

0


a source


I switched to Zend_Config_Xml as it is much easier for developers to figure out how to avoid the data than trying to work out a little weird .ini syntax.

Thanks everyone for the answers.

0


a source


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).

0


a source







All Articles