想做一个安装程序,里面有一项就是检测是否安装了gd库。如何写代码。也就是如何在一个php文件中,写几行代码,就能判断出环境是否已加载了gd库。

解决方案 »

  1.   

    #1.extension_loaded
    #2.function_exists //用来判断扩展库里的某个方法存不存在
      

  2.   

    楼上两位大侠已经说得很清楚了:
    function_exists()function_exists
    (PHP 4, PHP 5)function_exists — Return TRUE if the given function has been defined说明
    bool function_exists ( string $function_name )
    Checks the list of defined functions, both built-in (internal) and user-defined, for function_name. 参数function_name 
    The function name, as a string. 
    返回值
    Returns TRUE if function_name exists and is a function, FALSE otherwise. Note: This function will return FALSE for constructs, such as include_once() and echo(). 
    范例Example #1 function_exists() example<?php
    if (function_exists('imap_open')) {
        echo "IMAP functions are available.<br />\n";
    } else {
        echo "IMAP functions are not available.<br />\n";
    }
    ?> get_loaded_extensions ()get_loaded_extensions
    (PHP 4, PHP 5)get_loaded_extensions — Returns an array with the names of all modules compiled and loaded说明
    array get_loaded_extensions ([ bool $zend_extensions = false ] )
    This function returns the names of all the modules compiled and loaded in the PHP interpreter. 参数zend_extensions 
    Only return Zend extensions, if not then regular extensions, like mysqli are listed. Defaults to FALSE (return regular extensions). 
    返回值
    Returns an indexed array of all the modules names. 更新日志
    版本 说明 
    5.2.4 The optional zend_extensions parameter was added  
    范例Example #1 get_loaded_extensions() Example<?php
    print_r(get_loaded_extensions());
    ?> 
    以上例程的输出类似于:Array
    (
       [0] => xml
       [1] => wddx
       [2] => standard
       [3] => session
       [4] => posix
       [5] => pgsql
       [6] => pcre
       [7] => gd
       [8] => ftp
       [9] => db
       [10] => calendar
       [11] => bcmath
    )
      

  3.   

    你都不查手册的吗?extension_loaded
    (PHP 3 >= 3.0.10, PHP 4, PHP 5)extension_loaded -- Find out whether an extension is loaded
    Description
    bool extension_loaded ( string name )
    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;
        }
    }
    ?>  
     
      

  4.   

    get_loaded_extensions()
    函数搞定,这个是我这边打印出来的:Array
    (
        [0] => bcmath
        [1] => calendar
        [2] => com_dotnet
        [3] => ctype
        [4] => session
        [5] => filter
        [6] => ftp
        [7] => hash
        [8] => iconv
        [9] => json
        [10] => odbc
        [11] => pcre
        [12] => Reflection
        [13] => date
        [14] => libxml
        [15] => standard
        [16] => tokenizer
        [17] => zlib
        [18] => SimpleXML
        [19] => dom
        [20] => SPL
        [21] => wddx
        [22] => xml
        [23] => xmlreader
        [24] => xmlwriter
        [25] => apache2handler
        [26] => gd
        [27] => mbstring
        [28] => mssql
        [29] => mysql
        [30] => mysqli
        [31] => PDO
        [32] => pdo_mysql
        [33] => SQLite
        [34] => Zend Optimizer
    )