php - Syntax error using parse_ini_file() when file's value's contain exclamation points and equal signs -
php - Syntax error using parse_ini_file() when file's value's contain exclamation points and equal signs -
the function below takes "test-backup.ini" file, parses , inputs values db via update_option() method.
however, when ini file's values contain special characters exlamation points (!) , equal signs (=) (and others guess), throwing php syntax error @ parse_ini_file($file):
syntax error, unexpected "!", etc...
for example, given content test-backup.ini file...
[settings] line1 = asc line2 = /*.blog ul li {margin-bottom:0 !important;}*/ line3 = true line4 = <meta name="google-site-verification" content="" /> i syntax errors on line2 "!" , on line 4 "="
how should filter $file before passing parse_ini_file() deal these characters preserved when passed update_option() call?
all i've found far this:
characters {}|&~![()" must not used anywhere in key , have special meaning in value.
$file = wp_plugin_dir.'/test/test-backup.ini'; if (file_exists($file) && is_readable($file)) { $ini_array = parse_ini_file($file); //errors when value contains =, !, etc foreach ($ini_array $key=>$value) { update_option($key, $value); } echo 'the settings have been saved'; } else { echo 'alternate response here'; } ?>
you should set values between double quotes way:
line1 = asc line2 = "/*.blog ul li {margin-bottom:0 !important;}*/" line3 = true line4 = "<meta name=\"google-site-verification\" content=\"\" />" hope helps
php syntax-error ini
Comments
Post a Comment