tags:

views:

151

answers:

3

I have a config file that takes text warnings like follows:

warnings.1 = Please check the date

These are presented to the user as HTML. I need to embed a hyperlink like the following:

warnings.1 = <a href="http://foo.com/!FOO!/"&gt;check with foo</a>

I can't for the life of me figure out how to escape this such that parse_ini_file() can read it and get that string the way I want.

+1  A: 

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

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

Output:

foo.com%2F%21FOO%21%2F
JYelton
This still has issues due to being in the href="" attribute inside double quotes..
Ciaran McNulty
+1  A: 

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:

Can either be INI_SCANNER_NORMAL (default) or INI_SCANNER_RAW. If INI_SCANNER_RAW is supplied, then option values will not be parsed.

Changelog: 5.3.0 Added optional scanner_mode parameter.

So you're screwed if you're not on 5.3. Or you need to use a different implementation, parse_ini_file is not the only INI file parser for PHP.

just somebody
I'm actually using Zend_Config_Ini but reproduced the problem with parse_ini_file - I'm not actually using 5.3 yes so I guess I need to look at other options.
Ciaran McNulty
A: 

I've ended up switching to Zend_Config_Xml as it's a lot clearer to our developers how to escape data than trying to work out the slightly weird .ini syntax.

Thanks to all for answers.

Ciaran McNulty