讀取INI檔案
INI_STR(name) INI_INT(name)
/* {{{ PHP_INI */ PHP_INI_BEGIN() PHP_INI_ENTRY("safenet.url", "http://localhost/", PHP_INI_ALL, NULL) PHP_INI_ENTRY("safenet.key", "key01", PHP_INI_ALL, NULL) PHP_INI_END() /* }}} */ /* {{{ PHP_MINIT_FUNCTION */ PHP_MINIT_FUNCTION(safenet) { REGISTER_INI_ENTRIES(); return SUCCESS; } /* }}} */ /* {{{ PHP_MSHUTDOWN_FUNCTION */ PHP_MSHUTDOWN_FUNCTION(safenet) { UNREGISTER_INI_ENTRIES(); return SUCCESS; } /* }}} */ /* {{{ PHP_MINFO_FUNCTION */ PHP_MINFO_FUNCTION(safenet) { php_info_print_table_start(); php_info_print_table_header(2, "safenet support", "enabled"); php_info_print_table_row(2, "author", "Neo Chan<netkiller@msn.com>"); php_info_print_table_row(2, "safenet.url", INI_STR("safenet.url")); php_info_print_table_row(2, "safenet.key", INI_STR("safenet.key")); php_info_print_table_end(); /* Remove comments if you have entries in php.ini DISPLAY_INI_ENTRIES(); */ } /* }}} */
INI_STR取不到值的問題, 是因為REGISTER_INI_ENTRIES();沒有開啟
PHP_MINIT_FUNCTION(gt1) { /* If you have INI entries, uncomment these lines */ REGISTER_INI_ENTRIES(); init_class(TSRMLS_C); return SUCCESS; } PHP_MSHUTDOWN_FUNCTION(gt1) { /* uncomment this line if you have INI entries */ UNREGISTER_INI_ENTRIES(); return SUCCESS; }