CodeIgniter教程:CodeIgniter 兼容性函数
CodeIgniter 提供了一系列兼容性函数可以让你使用,它们只有在高版本的 PHP 中才有, 或者需要依赖其他的扩展才有。
由于是自己实现的,这些函数本身也可能有它自己的依赖性,但如果你的 PHP 中不提供这些函数时, 这些函数还是有用的。
注:和 公用函数 <common_functions> 一样,兼容性函数也一直可以访问,只要满足了他们的依赖条件。
这几个兼容性函数移植了 PHP 标准的 密码哈希扩展 的实现, 这些函数只有在 PHP 5.5 以后的版本中才有。
依赖性
常量
函数参考
password_get_info($hash)
参数: |
|
---|---|
返回: |
Information about the hashed password |
返回类型: |
array |
更多信息,请参考 PHP 手册中的 password_get_info() 函数
password_hash($password, $algo[, $options = array()])
参数: |
|
---|---|
返回: |
Hashed password or FALSE on failure |
返回类型: |
string |
更多信息,请参考 PHP 手册中的 password_hash() 函数
注:除非提供了你自己的有效盐值,该函数会依赖于一个可用的 CSPRNG 源(密码学安全的伪随机数生成器), 下面列表中的每一个都可以满足这点: - mcrypt_create_iv() with MCRYPT_DEV_URANDOM - openssl_random_pseudo_bytes() - /dev/arandom - /dev/urandom
password_needs_rehash()
参数: |
|
---|---|
返回: |
TRUE if the hash should be rehashed to match the given algorithm and options, FALSE otherwise |
返回类型: |
bool |
更多信息,请参考 PHP 手册中的 password_needs_rehash() 函数
password_verify($password, $hash)
参数: |
|
---|---|
返回: |
TRUE if the password matches the hash, FALSE if not |
返回类型: |
bool |
更多信息,请参考 PHP 手册中的 password_verify() 函数
兼容性函数移植了 hash_equals() 和 hash_pbkdf2() 的实现, 这两函数分别在 PHP 5.6 和 PHP 5.5 以后的版本中才有。
函数参考
hash_equals($known_string, $user_string)
参数: |
|
---|---|
返回: |
TRUE if the strings match, FALSE otherwise |
返回类型: |
string |
更多信息,请参考 PHP 手册中的 hash_equals() 函数
hash_pbkdf2($algo, $password, $salt, $iterations[, $length = 0[, $raw_output = FALSE]])
参数: |
|
---|---|
返回: |
Password-derived key or FALSE on failure |
返回类型: |
string |
更多信息,请参考 PHP 手册中的 hash_pbkdf2() 函数
这一系列兼容性函数提供了对 PHP 的 多字节字符串扩展 的有限支持, 由于可选的解决方法有限,所以只有几个函数是可用的。
注:如果没有指定字符集参数,默认使用 $config['charset'] 配置。
依赖性
重要:这个依赖是可选的,无论 iconv 扩展是否存在,这些函数都已经定义了, 如果 iconv 扩展不可用,它们会降级到非多字节字符串的函数版本。
重要:当设置了字符集时,该字符集必须被 iconv 支持,并且要设置成它可以识别的格式。
注:如果你需要判断是否支持真正的多字节字符串扩展,可以使用 MB_ENABLED 常量。
函数参考
mb_strlen($str[, $encoding = NULL])
参数: |
|
---|---|
返回: |
Number of characters in the input string or FALSE on failure |
返回类型: |
string |
更多信息,请参考 PHP 手册中的 mb_strlen() 函数
mb_strpos($haystack, $needle[, $offset = 0[, $encoding = NULL]])
参数: |
|
---|---|
返回: |
Numeric character position of where $needle was found or FALSE if not found |
返回类型: |
mixed |
更多信息,请参考 PHP 手册中的 mb_strpos() 函数
mb_substr($str, $start[, $length = NULL[, $encoding = NULL]])
参数: |
|
---|---|
返回: |
Portion of $str specified by $start and $length or FALSE on failure |
返回类型: |
string |
更多信息,请参考 PHP 手册中的 mb_substr() 函数
这一系列兼容性函数提供了一些高版本的 PHP 中才有的标准函数。
依赖性
函数参考
array_column(array $array, $column_key[, $index_key = NULL])
参数: |
|
---|---|
返回: |
An array of values representing a single column from the input array |
返回类型: |
array |
更多信息,请参考 PHP 手册中的 array_column() 函数
array_replace(array $array1[, ...])
参数: |
|
---|---|
返回: |
Modified array |
返回类型: |
array |
更多信息,请参考 PHP 手册中的 array_replace() 函数
array_replace_recursive(array $array1[, ...])
参数: |
|
---|---|
返回: |
Modified array |
返回类型: |
array |
更多信息,请参考 PHP 手册中的 array_replace_recursive() 函数
重要:只有 PHP 原生的函数才可以检测到无穷递归,如果你使用的是 PHP 5.3+ ,使用时要担心引用!
hex2bin($data)
参数: |
|
---|---|
返回: |
Binary representation of the given data |
返回类型: |
string |
更多信息,请参考 PHP 手册中的 hex2bin() 函数
quoted_printable_encode($str)
参数: |
|
---|---|
返回: |
8bit-encoded string |
返回类型: |
string |
更多信息,请参考 PHP 手册中的 quoted_printable_encode() 函数
全文详见:http://it-club.cn/post/493.html