extension_loaded

(PHP 4, PHP 5)

extension_loaded — Find out whether an extension is loaded

Описание

bool extension_loaded ( string $name )

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 !

Коментарии

// 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);
2024-11-12 05:10:45
http://php5.kiev.ua/manual/ru/function.extension-loaded.html

    Поддержать сайт на родительском проекте КГБ