1. PHP不需要使用var进行变量定义,但是在类里面定义属性是需要使用var进行定义的 2. 使用parse_ini_file解析自己的ini文件:http://cn.php.net/manual/zh/function.parse-ini-file.php 例子 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"
但在使用传如的变量时最好先检查一下变量是否存在
2、parse_ini_file()
读取ini格式的文件到数组,不包括注释
如果声明,是怎么个用法呢?
事先申明的话编译器就会预先为这个变量分配内存吧,不过在php这种脚本语言里应该起不到什么效果
1、用var $str;是错误的;
2、在函数或类中的变量,不事先定义(赋值)的话,进行判断等操作,Eclipse编辑器会提示该处变量没有初始化,用var $str也是不行的,而是要$str="";
但是在类里边却能用var声明
----------------------------------------------------------不是这样,这和你的php警告级别有关。通常服务器的警告级别为E_ALL ^ E_NOTICE。而你的设置打开了E_NOTICE。所以一切访问未初始化的变量都会警告。
2. 使用parse_ini_file解析自己的ini文件:http://cn.php.net/manual/zh/function.parse-ini-file.php
例子 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"
例子 2. parse_ini_file() 例子<?phpdefine('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
)
Array
(
[first_section] => Array
(
[one] => 1
[five] => 5
[animal] = Dodo bird
) [second_section] => Array
(
[path] => /usr/local/bin
[URL] => http://www.example.com/~username
))