# 兼容性函數
CodeIgniter 提供了一系列兼容性函數可以讓你使用,它們只有在高版本的 PHP 中才有, 或者需要依賴其他的擴展才有。
由于是自己實現的,這些函數本身也可能有它自己的依賴性,但如果你的 PHP 中不提供這些函數時, 這些函數還是有用的。
**注解**
和 公共函數 一樣,兼容性函數也一直可以訪問,只要滿足了他們的依賴條件。
# 密碼哈希
這幾個兼容性函數移植了 PHP 標準的 密碼哈希擴展 的實現, 這些函數只有在 PHP 5.5 以后的版本中才有。
# 依賴性
PHP 5.3.7
crypt() 函數需支持 CRYPT_BLOWFISH
# 常量
PASSWORD_BCRYPT
PASSWORD_DEFAULT
函數參考
**password_get_info**($hash)
參數: $hash (string) -- Password hash
返回: Information about the hashed password
返回類型:array
更多信息,請參考 PHP 手冊中的 password_get_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() 函數
**注解**
除非提供了你自己的有效的 Salt,該函數會依賴于一個可用的 CSPRNG 源(密碼學安全的偽隨機數生成器), 下面列表中的每一個都可以滿足這點: - mcrypt_create_iv() with MCRYPT_DEV_URANDOM - openssl_random_pseudo_bytes() - /dev/arandom - /dev/urandom
**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() 函數
**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() 函數
# 哈希(信息摘要)
兼容性函數移植了 hash_equals() 和 hash_pbkdf2() 的實現, 這兩函數分別在 PHP 5.6 和 PHP 5.5 以后的版本中才有。
依賴性
無
函數參考
**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() 函數
**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() 函數
# 多字節字符串
這一系列兼容性函數提供了對 PHP 的 多字節字符串擴展 的有限支持, 由于可選的解決方法有限,所以只有幾個函數是可用的。
**注解**
如果沒有指定字符集參數,默認使用 $config['charset'] 配置。
**依賴性**
iconv 擴展
**重要**
這個依賴是可選的,無論 iconv 擴展是否存在,這些函數都已經定義了, 如果 iconv 擴展不可用,它們會降級到非多字節字符串的函數版本。
**重要**
當設置了字符集時,該字符集必須被 iconv 支持,并且要設置成它可以識別的格式。
**注解**
如果你需要判斷是否支持真正的多字節字符串擴展,可以使用 MB_ENABLED 常量。
函數參考
**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() 函數
**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() 函數
**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() 函數
# 標準函數
這一系列兼容性函數提供了一些高版本的 PHP 中才有的標準函數。
# 依賴性
None
# 函數參考
**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() 函數
**hex2bin**($data)
參數: $data (array) -- Hexadecimal representation of data
返回: Binary representation of the given data
返回類型: string
更多信息,請參考 PHP 手冊中的 hex2bin() 函數
- 空白目錄
- 歡迎使用 CodeIgniter
- 安裝說明
- 下載CodeIgniter
- 安裝說明
- 從老版本升級
- 疑難解答
- CodeIgniter 概覽
- 開始
- CodeIgniter 是什么?
- 支持特性
- 應用程序流程圖
- 模型-視圖-控制器
- 架構目標
- 教程 - 內容提要
- 加載靜態內容
- 讀取新聞條目
- 創建新聞條目
- 結束語
- 向 CodeIgniter 貢獻你的力量
- 編寫 CodeIgniter 的文檔
- Developer's Certificate of Origin 1.1
- 常規主題
- CodeIgniter URL
- 控制器
- 保留名稱
- 視圖
- 模型
- 輔助函數
- 使用 CodeIgniter 類庫
- 創建類庫
- 使用 CodeIgniter 驅動器
- 創建驅動器
- 創建核心系統類
- 創建附屬類
- 鉤子 - 擴展框架核心
- 自動加載資源
- 公共函數
- 兼容性函數
- URI 路由
- 錯誤處理
- 網頁緩存
- 程序分析
- 以 CLI 方式運行
- 管理你的應用程序
- 處理多環境
- 在視圖文件中使用 PHP 替代語法
- 安全
- PHP 開發規范
- 類庫參考
- 基準測試類
- 緩存驅動器
- 日歷類
- 購物車類
- 配置類
- Email 類
- 加密類
- 加密類(新版)
- 文件上傳類
- 表單驗證類
- FTP 類
- 圖像處理類
- 輸入類
- Javascript 類
- 語言類
- 加載器類