(PHP 4, PHP 5, PHP 7)
parse_ini_file — ����һ�������ļ�
$filename
[, bool $process_sections
= false
[, int $scanner_mode
= INI_SCANNER_NORMAL
]] ) : array
parse_ini_file() ����һ����
filename
ָ���� ini
�ļ����������е�������Ϊһ���������鷵�ء�
ini �ļ��Ľṹ�� php.ini �����ơ�
filename
Ҫ������ ini �ļ����ļ�����
process_sections
���������
process_sections
������Ϊ
TRUE
�����õ�һ����ά���飬�����������ļ���ÿһ�ڵ����ƺ����á�process_sections
��Ĭ��ֵ�� FALSE
��
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.
�ɹ�ʱ�Թ������� array �������ã�ʧ��ʱ���� FALSE
��
�汾 | ˵�� |
---|---|
5.3.0 |
Added optional scanner_mode parameter.
Single quotes may now be used around variable assignments.
Hash marks (#) may no longer be used as comments
and will throw a deprecation warning if used.
|
5.2.7 |
On syntax error this function will return FALSE rather than an empty
array.
|
5.2.4 | ��������ɵļ�����С�����ᱻ PHP ������������������� 0 ��ͷ�����ֻᱻ�����˽��ƶ��� 0x ��ͷ�Ļᱻ����ʮ�����ơ� |
5.0.0 | �ú���Ҳ��ʼ����ѡ��ֵ�ڵ����С� |
4.2.1 | ������Ҳ��ʼ�ܵ���ȫģʽ�� open_basedir ��Ӱ�졣 |
Example #1 sample.ini ������
; This is a sample configuration file ; Comments start with ';', as in php.ini [first_section] one = 1 five = 5 animal = BIRD [second_section] path = "/usr/local/bin" URL = "http://www.example.com/~username" [third_section] phpversion[] = "5.0" phpversion[] = "5.1" phpversion[] = "5.2" phpversion[] = "5.3"
Example #2 parse_ini_file() ����
����Ҳ������ ini �ļ��б������������������� parse_ini_file() ֮ǰ�����˳�����Ϊ ini ��ֵ�����ᱻ���ɵ������ȥ��ֻ�� ini ��ֵ�ᱻ��ֵ�����磺
<?php
define('BIRD', 'Dodo bird');
// Parse without sections
$ini_array = parse_ini_file("sample.ini");
print_r($ini_array);
// Parse with sections
$ini_array = parse_ini_file("sample.ini", true);
print_r($ini_array);
?>
�������̵���������ڣ�
Array ( [one] => 1 [five] => 5 [animal] => Dodo bird [path] => /usr/local/bin [URL] => http://www.example.com/~username [phpversion] => Array ( [0] => 5.0 [1] => 5.1 [2] => 5.2 [3] => 5.3 ) ) Array ( [first_section] => Array ( [one] => 1 [five] => 5 [animal] => Dodo bird ) [second_section] => Array ( [path] => /usr/local/bin [URL] => http://www.example.com/~username ) [third_section] => Array ( [phpversion] => Array ( [0] => 5.0 [1] => 5.1 [2] => 5.2 [3] => 5.3 ) ) )
Example #3 parse_ini_file() parsing a php.ini file
<?php
// A simple function used for comparing the results below
function yesno($expression)
{
return($expression ? 'Yes' : 'No');
}
// Get the path to php.ini using the php_ini_loaded_file()
// function available as of PHP 5.2.4
$ini_path = php_ini_loaded_file();
// Parse php.ini
$ini = parse_ini_file($ini_path);
// Print and compare the values, note that using get_cfg_var()
// will give the same results for parsed and loaded here
echo '(parsed) magic_quotes_gpc = ' . yesno($ini['magic_quotes_gpc']) . PHP_EOL;
echo '(loaded) magic_quotes_gpc = ' . yesno(get_cfg_var('magic_quotes_gpc')) . PHP_EOL;
?>
�������̵���������ڣ�
(parsed) magic_quotes_gpc = Yes (loaded) magic_quotes_gpc = Yes
Note:
�������� php.ini �ļ�û�й�ϵ�����ļ������нű�ʱ���Ѿ�������ˡ�����������������ȡ���Լ���Ӧ�ó���������ļ���
Note:
��� ini �ļ��е�ֵ�����κη���ĸ���ֵ��ַ�����Ҫ��������˫�����У�"����
Note: ��Щ�����ֲ�����Ϊ ini �ļ��еļ�����������null��yes��no��true �� false��ֵΪ null��no �� false ��Ч�� ""��ֵΪ yes �� true ��Ч�� "1"���ַ� {}|&~![()" Ҳ�������ڼ������κεط���������Щ�ַ���ѡ��ֵ��������������塣