Virtuoso NoShow
Virtuoso NoShow

Reputation: 71

parse_ini_file() keep outputing an error when i use it

Okay for some reason i was using parse_ini_file() and i keep getting an error message, it says

Warning: syntax error, unexpected END_OF_LINE in app/config.ini on line 10 in C:\xampp\htdocs\index.php on line 2

My config.ini contains

[meta]
keywords=%nodata%
description=%nodata%
author=Nicholas English
[email protected]
robots=all
dnsprefetch=off
cachecontrol=no-cache
fragment=!

My index.php contains

<?php
$config = parse_ini_file("app/config.ini", true);
$meta = $config['meta'];
?>

I have search on google and no luck and i have tried doing it my self but it still wont work.

Any help would be amazing, thank you in advance.

Upvotes: 2

Views: 853

Answers (1)

Ruslan Osmanov
Ruslan Osmanov

Reputation: 21502

Use INI_SCANNER_RAW option:

$config = parse_ini_file("app/config.ini", true, INI_SCANNER_RAW);

In default mode (INI_SCANNER_NORMAL) PHP prohibits exclamation mark in unquoted value:

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

So whether use the raw scanner, or quote the values with non-alphanumeric values, e.g.:

fragment="!"

Upvotes: 3

Related Questions