I'm having开发者_如何学运维 problems loading the parse_ini_file, currently I have registered a path in my include-path but there was an unexpected behavior parse_ini_file (didn't load)
(A little note: using phpunit to test, don't know if it affects the loading)
Example:
Path is: "C:/mydevelopworkspace/project/"
In that path there are well, php files, and an ini that specifies many folders, thing is, when I run parse_ini_file I get an error, but when I do:
require_once 'Project/Config.ini';
It outputs the content, unlike parse_ini_file which doesn't really detects it =/ could anyone suggests me a workaround for this or an idea on where to look? Same thing happens with file_get_contents...
"Include paths" are the paths to search when doing an include, include_once, require or require_once.
All other functions that operate on files do not search the include path, including parse_ini_file. You'll need to specify the file location yourself.
You can change the current working directory so that when you do your parse_ini_file call, the working directory is the right one.
<?php
$cDir = getcwd();
// Changing the directory to your custom one //
chdir('C:/mydevelopworkspace/');
$data = parse_ini_file('Project/Config.ini');
// Reseting the current working directory to the previous one //
chdir($cDir);
?>
There is a PHP-Function called stream_resolve_include_path()
. With this you are able to open files according to the PHP-Include-Path
精彩评论