extension_loaded
(PHP 4, PHP 5)
extension_loaded — Find out whether an extension is loaded
Описание
Finds out whether the extension is loaded.
Список параметров
- name
-
The extension name.
You can see the names of various extensions by using phpinfo() or if you're using the CGI or CLI version of PHP you can use the -m switch to list all available extensions:
$ php -m [PHP Modules] xml tokenizer standard sockets session posix pcre overload mysql mbstring ctype [Zend Modules]
Возвращаемые значения
Returns TRUE if the extension identified by name is loaded, FALSE otherwise.
Примеры
Пример #1 extension_loaded() example
<?php
if (!extension_loaded('gd')) {
if (!dl('gd.so')) {
exit;
}
}
?>
Примечания
Замечание: extension_loaded() uses the internal extension name to test whether a certain extension is available or not. Most internal extension names are written in lower case but there may be extension available which also use uppercase letters. Be warned that this function compares case sensitive !
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Изменение поведения PHP
- PHP Опции и Информация
- assert_options
- assert
- cli_get_process_title
- cli_set_process_title
- dl
- extension_loaded
- gc_collect_cycles
- gc_disable
- gc_enable
- gc_enabled
- gc_mem_caches
- get_cfg_var
- get_current_user
- get_defined_constants
- get_extension_funcs
- get_include_path
- get_included_files
- get_loaded_extensions
- get_magic_quotes_gpc
- get_magic_quotes_runtime
- get_required_files
- get_resources
- getenv
- getlastmod
- getmygid
- getmyinode
- getmypid
- getmyuid
- getopt
- getrusage
- ini_alter
- ini_get_all
- ini_get
- ini_restore
- ini_set
- magic_quotes_runtime
- main
- memory_get_peak_usage
- memory_get_usage
- php_ini_loaded_file
- php_ini_scanned_files
- php_logo_guid
- php_sapi_name
- php_uname
- phpcredits
- phpinfo
- phpversion
- putenv
- restore_include_path
- set_include_path
- set_magic_quotes_runtime
- set_time_limit
- sys_get_temp_dir
- version_compare
- zend_logo_guid
- zend_thread_id
- zend_version
Коментарии
// Checks php extension, output any warnings
// For applications that requires certain extensions
function checkExtension($mod, $use = '', $warn = false, $fix = true) {
if (empty($mod)) return false;
if (extension_loaded($mod)) return true;
$out = 'Please enable '.$mod.' : '.$use.'<br>';
if ($fix) {
if (function_exists("dl")) {
$ok = @dl($mod);
if ($ok) $out .= 'Extension temporary enabled'; else $out .= 'Unable to start the extension';
} else {
$out .= 'Unable to internally started any extension';
}
}
if ($warn) {
echo '<span class="error">'. $out .'</span><br>';
}
}
// examples
checkExtension('','used to access email',true,true);
checkExtension('imap','used to access email',true,true);
checkExtension('iconv','used in mail decoding',true,true);
checkExtension('curl','curl used to get some https content',true,true);
checkExtension('zip','used to send zip data',true,true);
checkExtension('zlib','gzopen used to unzip downloads',true,true);
checkExtension('openssl','allows https with file_get_contents and fopen',true,true);
checkExtension('sockets','low level sockets',true,true);
checkExtension('mysqli','to access database',true,true);