CodeIgniter 兼容性函數(shù)

2018-07-21 15:37 更新

兼容性函數(shù)

CodeIgniter 提供了一系列兼容性函數(shù)可以讓你使用,它們只有在高版本的 PHP 中才有, 或者需要依賴其他的擴展才有。

由于是自己實現(xiàn)的,這些函數(shù)本身也可能有它自己的依賴性,但如果你的 PHP 中不提供這些函數(shù)時, 這些函數(shù)還是有用的。

注解

和 公用函數(shù)  一樣,兼容性函數(shù)也一直可以訪問,只要滿足了他們的依賴條件。

密碼哈希

這幾個兼容性函數(shù)移植了 PHP 標準的 密碼哈希擴展 的實現(xiàn), 這些函數(shù)只有在 PHP 5.5 以后的版本中才有。

依賴性

  • PHP 5.3.7
  • crypt() 函數(shù)需支持 CRYPT_BLOWFISH

常量

  • PASSWORD_BCRYPT
  • PASSWORD_DEFAULT

函數(shù)參考

password_get_info($hash)

參數(shù):

  • $hash (string) -- Password hash

返回: Information about the hashed password

返回類型: array

更多信息,請參考 PHP 手冊中的 password_get_info() 函數(shù)

password_hash($password, $algo[, $options = array()])

參數(shù):

  • $password (string) -- Plain-text password
  • $algo (int) -- Hashing algorithm
  • $options (array) -- Hashing options

返回: Hashed password or FALSE on failure

返回類型: string

更多信息,請參考 PHP 手冊中的 password_hash() 函數(shù)

注解

除非提供了你自己的有效鹽值,該函數(shù)會依賴于一個可用的 CSPRNG 源(密碼學(xué)安全的偽隨機數(shù)生成器), 下面列表中的每一個都可以滿足這點: - mcrypt_create_iv() with MCRYPT_DEV_URANDOM - openssl_random_pseudo_bytes() - /dev/arandom - /dev/urandom

password_needs_rehash()

參數(shù):

  • $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() 函數(shù)

password_verify($password, $hash)

參數(shù):

  • $password (string) -- Plain-text password
  • $hash (string) -- Password hash

返回: TRUE if the password matches the hash, FALSE if not
返回類型: bool

更多信息,請參考 PHP 手冊中的 password_verify() 函數(shù)

哈希(信息摘要)

兼容性函數(shù)移植了 hash_equals() 和 hash_pbkdf2() 的實現(xiàn), 這兩函數(shù)分別在 PHP 5.6 和 PHP 5.5 以后的版本中才有。

依賴性

函數(shù)參考

hash_equals($known_string, $user_string)

參數(shù):

  • $known_string (string) -- Known string
  • $user_string (string) -- User-supplied string

返回: TRUE if the strings match, FALSE otherwise

返回類型: string

更多信息,請參考 PHP 手冊中的 hash_equals() 函數(shù)

hash_pbkdf2($algo, $password, $salt, $iterations[, $length = 0[, $raw_output = FALSE]])

參數(shù):

  • $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() 函數(shù)

多字節(jié)字符串

這一系列兼容性函數(shù)提供了對 PHP 的 多字節(jié)字符串擴展 的有限支持, 由于可選的解決方法有限,所以只有幾個函數(shù)是可用的。

注解

如果沒有指定字符集參數(shù),默認使用 $config['charset'] 配置。

依賴性

重要
這個依賴是可選的,無論 iconv 擴展是否存在,這些函數(shù)都已經(jīng)定義了, 如果 iconv 擴展不可用,它們會降級到非多字節(jié)字符串的函數(shù)版本。

重要
當設(shè)置了字符集時,該字符集必須被 iconv 支持,并且要設(shè)置成它可以識別的格式。

注解

如果你需要判斷是否支持真正的多字節(jié)字符串擴展,可以使用 MB_ENABLED 常量。

函數(shù)參考

mb_strlen($str[, $encoding = NULL])

參數(shù):

  • $str (string) -- Input string
  • $encoding (string) -- Character set

返回: Number of characters in the input string or FALSE on failure
返回類型: string

更多信息,請參考 PHP 手冊中的 mb_strlen() 函數(shù)

mb_strpos($haystack, $needle[, $offset = 0[, $encoding = NULL]])

參數(shù):

  • $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() 函數(shù)

mb_substr($str, $start[, $length = NULL[, $encoding = NULL]])

參數(shù):

  • $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() 函數(shù)

標準函數(shù)

這一系列兼容性函數(shù)提供了一些高版本的 PHP 中才有的標準函數(shù)。

依賴性

  • None

函數(shù)參考

array_column(array $array, $column_key[, $index_key = NULL])

參數(shù):

  • $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() 函數(shù)

array_replace(array $array1[, ...])

參數(shù):

  • $array1 (array) -- Array in which to replace elements
  • ... (array) -- Array (or multiple ones) from which to extract elements

返回: Modified array

返回類型: array

更多信息,請參考 PHP 手冊中的 array_replace() 函數(shù)

array_replace_recursive(array $array1[, ...])

參數(shù):

  • $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() 函數(shù)

重要
只有 PHP 原生的函數(shù)才可以檢測到無窮遞歸,如果你使用的是 PHP 5.3+ ,使用時要擔心引用!

hex2bin($data)

參數(shù):

  • $data (array) -- Hexadecimal representation of data

返回: Binary representation of the given data

返回類型: string

更多信息,請參考 PHP 手冊中的 hex2bin() 函數(shù)

quoted_printable_encode($str)

參數(shù):

  • $str (string) -- Input string

返回:

8bit-encoded string

返回類型: string

更多信息,請參考 PHP 手冊中的 quoted_printable_encode() 函數(shù)

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號