| Line 1... |
Line 1... |
| 1 |
<?php |
1 |
<?php |
| 2 |
// +----------------------------------------------------------------------+ |
2 |
// +----------------------------------------------------------------------+ |
| 3 |
// | PHP Version 4 | |
3 |
// | PHP Version 4 | |
| 4 |
// +----------------------------------------------------------------------+ |
4 |
// +----------------------------------------------------------------------+ |
| 5 |
// | Copyright (c) 1997-2004 The PHP Group | |
5 |
// | Copyright (c) 1997-2004 The PHP Group | |
| 6 |
// +----------------------------------------------------------------------+ |
6 |
// +----------------------------------------------------------------------+ |
| 7 |
// | This source file is subject to version 3.0 of the PHP license, | |
7 |
// | This source file is subject to version 3.0 of the PHP license, | |
| 8 |
// | that is bundled with this package in the file LICENSE, and is | |
8 |
// | that is bundled with this package in the file LICENSE, and is | |
| 9 |
// | available at through the world-wide-web at | |
9 |
// | available at through the world-wide-web at | |
| 10 |
// | http://www.php.net/license/3_0.txt. | |
10 |
// | http://www.php.net/license/3_0.txt. | |
| 11 |
// | If you did not receive a copy of the PHP license and are unable to | |
11 |
// | If you did not receive a copy of the PHP license and are unable to | |
| 12 |
// | obtain it through the world-wide-web, please send a note to | |
12 |
// | obtain it through the world-wide-web, please send a note to | |
| 13 |
// | license@php.net so we can mail you a copy immediately. | |
13 |
// | license@php.net so we can mail you a copy immediately. | |
| 14 |
// +----------------------------------------------------------------------+ |
14 |
// +----------------------------------------------------------------------+ |
| 15 |
// | Authors: Aidan Lister <aidan@php.net> | |
15 |
// | Authors: Aidan Lister <aidan@php.net> | |
| 16 |
// +----------------------------------------------------------------------+ |
16 |
// +----------------------------------------------------------------------+ |
| 17 |
// |
17 |
// |
| 18 |
// $Id: ini_get_all.php,v 1.3 2005/01/26 04:55:13 aidan Exp $ |
18 |
// $Id: ini_get_all.php,v 1.3 2005/01/26 04:55:13 aidan Exp $ |
| 19 |
|
19 |
|
| 20 |
|
20 |
|
| 21 |
/** |
21 |
/** |
| 22 |
* Replace ini_get_all() |
22 |
* Replace ini_get_all() |
| 23 |
* |
23 |
* |
| 24 |
* @category PHP |
24 |
* @category PHP |
| 25 |
* @package PHP_Compat |
25 |
* @package PHP_Compat |
| 26 |
* @link http://php.net/function.ini_get_all |
26 |
* @link http://php.net/function.ini_get_all |
| 27 |
* @author Aidan Lister <aidan@php.net> |
27 |
* @author Aidan Lister <aidan@php.net> |
| 28 |
* @version $Revision: 1.3 $ |
28 |
* @version $Revision: 1.3 $ |
| 29 |
* @since PHP 4.2.0 |
29 |
* @since PHP 4.2.0 |
| 30 |
* @require PHP 4.0.0 (user_error) |
30 |
* @require PHP 4.0.0 (user_error) |
| 31 |
*/ |
31 |
*/ |
| 32 |
if (!function_exists('ini_get_all')) { |
32 |
if (!function_exists('ini_get_all')) { |
| 33 |
function ini_get_all($extension = null) |
33 |
function ini_get_all($extension = null) |
| 34 |
{ |
34 |
{ |
| 35 |
// Sanity check |
35 |
// Sanity check |
| 36 |
if (!is_scalar($extension)) { |
36 |
if (!is_scalar($extension)) { |
| 37 |
user_error('ini_get_all() expects parameter 1 to be string, ' . |
37 |
user_error('ini_get_all() expects parameter 1 to be string, ' . |
| 38 |
gettype($extension) . ' given', E_USER_WARNING); |
38 |
gettype($extension) . ' given', E_USER_WARNING); |
| 39 |
return false; |
39 |
return false; |
| 40 |
} |
40 |
} |
| 41 |
|
41 |
|
| 42 |
// Get the location of php.ini |
42 |
// Get the location of php.ini |
| 43 |
ob_start(); |
43 |
ob_start(); |
| 44 |
phpinfo(INFO_GENERAL); |
44 |
phpinfo(INFO_GENERAL); |
| 45 |
$info = ob_get_contents(); |
45 |
$info = ob_get_contents(); |
| 46 |
ob_clean(); |
46 |
ob_clean(); |
| 47 |
$info = explode("\n", $info); |
47 |
$info = explode("\n", $info); |
| 48 |
$line = array_values(preg_grep('#php.ini#', $info)); |
48 |
$line = array_values(preg_grep('#php.ini#', $info)); |
| 49 |
list (, $value) = explode('<td class="v">', $line[0]); |
49 |
list (, $value) = explode('<td class="v">', $line[0]); |
| 50 |
$inifile = trim(strip_tags($value)); |
50 |
$inifile = trim(strip_tags($value)); |
| 51 |
|
51 |
|
| 52 |
// Parse |
52 |
// Parse |
| 53 |
if ($extension !== null) { |
53 |
if ($extension !== null) { |
| 54 |
$ini_all = parse_ini_file($inifile, true); |
54 |
$ini_all = parse_ini_file($inifile, true); |
| 55 |
|
55 |
|
| 56 |
// Lowercase extension keys |
56 |
// Lowercase extension keys |
| 57 |
foreach ($ini_all as $key => $value) { |
57 |
foreach ($ini_all as $key => $value) { |
| 58 |
$ini_arr[strtolower($key)] = $value; |
58 |
$ini_arr[strtolower($key)] = $value; |
| 59 |
} |
59 |
} |
| 60 |
|
60 |
|
| 61 |
$ini = $ini_arr[$extension]; |
61 |
$ini = $ini_arr[$extension]; |
| 62 |
} else { |
62 |
} else { |
| 63 |
$ini = parse_ini_file($inifile); |
63 |
$ini = parse_ini_file($inifile); |
| 64 |
} |
64 |
} |
| 65 |
|
65 |
|
| 66 |
// Order |
66 |
// Order |
| 67 |
$ini_lc = array_map('strtolower', array_keys($ini)); |
67 |
$ini_lc = array_map('strtolower', array_keys($ini)); |
| 68 |
array_multisort($ini_lc, SORT_ASC, SORT_STRING, $ini); |
68 |
array_multisort($ini_lc, SORT_ASC, SORT_STRING, $ini); |
| 69 |
|
69 |
|
| 70 |
// Format |
70 |
// Format |
| 71 |
$info = array(); |
71 |
$info = array(); |
| 72 |
foreach ($ini as $key => $value) { |
72 |
foreach ($ini as $key => $value) { |
| 73 |
$info[$key] = array( |
73 |
$info[$key] = array( |
| 74 |
'global_value' => $value, |
74 |
'global_value' => $value, |
| 75 |
'local_value' => ini_get($key), |
75 |
'local_value' => ini_get($key), |
| 76 |
// No way to know this |
76 |
// No way to know this |
| 77 |
'access' => -1 |
77 |
'access' => -1 |
| 78 |
); |
78 |
); |
| 79 |
} |
79 |
} |
| 80 |
|
80 |
|
| 81 |
return $info; |
81 |
return $info; |
| 82 |
} |
82 |
} |
| 83 |
} |
83 |
} |
| 84 |
|
84 |
|
| 85 |
?> |
85 |
?> |
| 86 |
|
86 |
|