企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 兼容性函数 CodeIgniter 提供了一系列兼容性函数可以让你使用,它们只有在高版本的 PHP 中才有, 或者需要依赖其他的扩展才有。 由于是自己实现的,这些函数本身也可能有它自己的依赖性,但如果你的 PHP 中不提供这些函数时, 这些函数还是有用的。 注解 和 公用函数  一样,兼容性函数也一直可以访问,只要满足了他们的依赖条件。 [TOC=2,3] ## 密码哈希 这几个兼容性函数移植了 PHP 标准的 [密码哈希扩展](http://php.net/password) 的实现, 这些函数只有在 PHP 5.5 以后的版本中才有。 ### 依赖性 * PHP 5.3.7 * crypt() 函数需支持 CRYPT_BLOWFISH ### 常量 * PASSWORD_BCRYPT * PASSWORD_DEFAULT ### 函数参考 >[info] ### password_get_info($hash) 参数: * **$hash** (string) -- Password hash 返回: Information about the hashed password 返回类型: array 更多信息,请参考 [PHP 手册中的 password_get_info() 函数](http://php.net/password_get_info) >[info] ### password_hash($password, $algo[, $options = array()]) 参数: * **$password** (string) -- Plain-text password * **$algo** (int) -- Hashing algorithm * **$options** (array) -- Hashing options 返回: Hashed password or FALSE on failure 返回类型: string 更多信息,请参考 [PHP 手册中的 password_hash() 函数](http://php.net/password_hash) 注解 除非提供了你自己的有效盐值,该函数会依赖于一个可用的 CSPRNG 源(密码学安全的伪随机数生成器), 下面列表中的每一个都可以满足这点: - mcrypt_create_iv() with MCRYPT_DEV_URANDOM - openssl_random_pseudo_bytes() - /dev/arandom - /dev/urandom >[info] ### password_needs_rehash() 参数: * **$hash** (string) -- Password hash * **$algo** (int) -- Hashing algorithm * **$options** (array) -- Hashing options 返回: TRUE if the hash should be rehashed to match the given algorithm and options, FALSE otherwise 返回类型: bool 更多信息,请参考 [PHP 手册中的 password_needs_rehash() 函数](http://php.net/password_needs_rehash) >[info] ### password_verify($password, $hash) 参数: * **$password** (string) -- Plain-text password * **$hash** (string) -- Password hash 返回: TRUE if the password matches the hash, FALSE if not 返回类型: bool 更多信息,请参考 [PHP 手册中的 password_verify() 函数](http://php.net/password_verify) ## 哈希(信息摘要) 兼容性函数移植了 hash_equals() 和 hash_pbkdf2() 的实现, 这两函数分别在 PHP 5.6 和 PHP 5.5 以后的版本中才有。 ### 依赖性 * 无 ### 函数参考 >[info] ### hash_equals($known_string, $user_string) 参数: * **$known_string** (string) -- Known string * **$user_string** (string) -- User-supplied string 返回: TRUE if the strings match, FALSE otherwise 返回类型: string 更多信息,请参考 [PHP 手册中的 hash_equals() 函数](http://php.net/hash_equals) >[info] ### hash_pbkdf2($algo, $password, $salt, $iterations[, $length = 0[, $raw_output = FALSE]]) 参数: * **$algo** (string) -- Hashing algorithm * **$password** (string) -- Password * **$salt** (string) -- Hash salt * **$iterations** (int) -- Number of iterations to perform during derivation * **$length** (int) -- Output string length * **$raw_output** (bool) -- Whether to return raw binary data 返回: Password-derived key or FALSE on failure 返回类型: string 更多信息,请参考 [PHP 手册中的 hash_pbkdf2() 函数](http://php.net/hash_pbkdf2) ## 多字节字符串 这一系列兼容性函数提供了对 PHP 的 [多字节字符串扩展](http://php.net/mbstring) 的有限支持, 由于可选的解决方法有限,所以只有几个函数是可用的。 > 注解 > 如果没有指定字符集参数,默认使用 $config['charset'] 配置。 ### 依赖性 * [iconv](http://php.net/iconv) 扩展 >[danger] 重要 > 这个依赖是可选的,无论 iconv 扩展是否存在,这些函数都已经定义了, 如果 iconv 扩展不可用,它们会降级到非多字节字符串的函数版本。 > 重要 > 当设置了字符集时,该字符集必须被 iconv 支持,并且要设置成它可以识别的格式。 > 注解 > 如果你需要判断是否支持真正的多字节字符串扩展,可以使用 MB_ENABLED 常量。 ### 函数参考 >[info] ### mb_strlen($str[, $encoding = NULL]) 参数: * **$str** (string) -- Input string * **$encoding** (string) -- Character set 返回: Number of characters in the input string or FALSE on failure 返回类型: string 更多信息,请参考 [PHP 手册中的 mb_strlen() 函数](http://php.net/mb_strlen) >[info] ### mb_strpos($haystack, $needle[, $offset = 0[, $encoding = NULL]]) 参数: * **$haystack** (string) -- String to search in * **$needle** (string) -- Part of string to search for * **$offset** (int) -- Search offset * **$encoding** (string) -- Character set 返回: Numeric character position of where $needle was found or FALSE if not found 返回类型: mixed 更多信息,请参考 [PHP 手册中的 mb_strpos() 函数](http://php.net/mb_strpos) >[info] ### mb_substr($str, $start[, $length = NULL[, $encoding = NULL]]) 参数: * **$str** (string) -- Input string * **$start** (int) -- Position of first character * **$length** (int) -- Maximum number of characters * **$encoding** (string) -- Character set 返回: Portion of $str specified by $start and $length or FALSE on failure 返回类型: string 更多信息,请参考 [PHP 手册中的 mb_substr() 函数](http://php.net/mb_substr) ## 标准函数 这一系列兼容性函数提供了一些高版本的 PHP 中才有的标准函数。 ### 依赖性 * None ### 函数参考 >[info] ### array_column(array $array, $column_key[, $index_key = NULL]) 参数: * **$array** (array) -- Array to fetch results from * **$column_key** (mixed) -- Key of the column to return values from * **$index_key** (mixed) -- Key to use for the returned values 返回: An array of values representing a single column from the input array 返回类型: array 更多信息,请参考 [PHP 手册中的 array_column() 函数](http://php.net/array_column) >[info] ### array_replace(array $array1[, ...]) 参数: * **$array1** (array) -- Array in which to replace elements * **...** (array) -- Array (or multiple ones) from which to extract elements 返回: Modified array 返回类型: array 更多信息,请参考 [PHP 手册中的 array_replace() 函数](http://php.net/array_replace) >[info] ### array_replace_recursive(array $array1[, ...]) 参数: * **$array1** (array) -- Array in which to replace elements * **...** (array) -- Array (or multiple ones) from which to extract elements 返回: Modified array 返回类型: array 更多信息,请参考 [PHP 手册中的 array_replace_recursive() 函数](http://php.net/array_replace_recursive) >[danger] 重要 > 只有 PHP 原生的函数才可以检测到无穷递归,如果你使用的是 PHP 5.3+ ,使用时要担心引用! >[info] ### hex2bin($data) 参数: * **$data** (array) -- Hexadecimal representation of data 返回: Binary representation of the given data 返回类型: string 更多信息,请参考 [PHP 手册中的 hex2bin() 函数](http://php.net/hex2bin) >[info] ### quoted_printable_encode($str) 参数: * **$str** (string) -- Input string 返回: 8bit-encoded string 返回类型: string 更多信息,请参考 [PHP 手册中的 quoted_printable_encode() 函数](http://php.net/quoted_printable_encode)