# 兼容性函數
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)
- 歡迎使用 CodeIgniter
- 安裝說明
- 下載 CodeIgniter
- 安裝說明
- 從老版本升級
- 疑難解答
- CodeIgniter 概覽
- CodeIgniter 將從這里開始
- CodeIgniter 是什么?
- 支持特性
- 應用程序流程圖
- 模型-視圖-控制器
- 設計與架構目標
- 教程 - 內容提要
- 加載靜態內容
- 讀取新聞條目
- 創建新聞條目
- 結束語
- 常規主題
- CodeIgniter URL
- 控制器
- 保留名稱
- 視圖
- 模型
- 輔助函數
- 使用 CodeIgniter 類庫
- 創建類庫
- 使用 CodeIgniter 驅動器
- 創建驅動器
- 創建核心系統類
- 創建附屬類
- 鉤子 - 擴展框架核心
- 自動加載資源
- 公共函數
- 兼容性函數
- URI 路由
- 錯誤處理
- 網頁緩存
- 程序分析
- 以 CLI 方式運行
- 管理你的應用程序
- 處理多環境
- 在視圖文件中使用 PHP 替代語法
- 安全
- PHP 開發規范
- 類庫參考
- 基準測試類
- 緩存驅動器
- 日歷類
- 購物車類
- 配置類
- Email 類
- 加密類
- 加密類(新版)
- 文件上傳類
- 表單驗證類
- FTP 類
- 圖像處理類
- 輸入類
- Javascript 類
- 語言類
- 加載器類
- 遷移類
- 輸出類
- 分頁類
- 模板解析類
- 安全類
- Session 類
- HTML 表格類
- 引用通告類
- 排版類
- 單元測試類
- URI 類
- 用戶代理類
- XML-RPC 與 XML-RPC 服務器類
- Zip 編碼類
- 數據庫參考
- 數據庫快速入門: 示例代碼
- 數據庫配置
- 連接你的數據庫
- 查詢
- 生成查詢結果
- 查詢輔助函數
- 查詢構造器類
- 事務
- 數據庫元數據
- 自定義函數調用
- 數據庫緩存類
- 數據庫工廠類
- 數據庫工具類
- 數據庫驅動器參考
- 輔助函數參考
- 數組輔助函數
- 驗證碼輔助函數
- Cookie 輔助函數
- 日期輔助函數
- 目錄輔助函數
- 下載輔助函數
- 郵件輔助函數
- 文件輔助函數
- 表單輔助函數
- HTML 輔助函數
- 語言輔助函數
- Inflector 輔助函數
- 數字輔助函數
- 路徑輔助函數
- 安全輔助函數
- 表情輔助函數
- 字符串輔助函數
- 文本輔助函數
- 排版輔助函數
- URL 輔助函數
- XML 輔助函數
- 向 CodeIgniter 貢獻你的力量