負載,並得到配置或設置文件,您可以使用parse_ini_file:
parse_ini_file - 解析一個配置文件
實例#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"
的index.php內容
<?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
)
)
)
簡單的類定義
<?php
class SimpleClass
{
// property declaration and access from all method
public $var = 'a default value';
public $ini_array = parse_ini_file("sample.ini");
// method declaration
public function displayVar() {
echo $this->var;
print_r($this->$ini_array);
}
}
$Simpleclass = new SimpleClass();
$Simpleclass->displayVar();
?>
什麼是'variable_get'?這是在[標籤:Drupal]? – Phil