新聞中心

創(chuàng)新互聯(lián)公司長期為1000多家客戶提供的網(wǎng)站建設服務,團隊從業(yè)經(jīng)驗10年,關注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務;打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為丹鳳企業(yè)提供專業(yè)的成都網(wǎng)站設計、網(wǎng)站建設,丹鳳網(wǎng)站改版等技術服務。擁有十余年豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。
str_ireplace() 和 str_replace() 函數(shù)
str_ireplace() 和 str_replace 使用新的字符串替換原來字符串中指定的特定字符串,str_replace 區(qū)分大小寫,str_ireplace() 不區(qū)分大小寫,兩者語法相似。
str_ireplace() 的語法如下:
mixed str_ireplace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )
該函數(shù)返回一個字符串或者數(shù)組。該字符串或數(shù)組是將 subject 中全部的 search 用 replace 替換(忽略大小寫)之后的結果。參數(shù) count 表示執(zhí)行替換的次數(shù)。
使用示例如下:
執(zhí)行以上代碼的輸出結果為:
hi,world,hi,world
substr_replace() 函數(shù)
substr_replace() 函數(shù)的語法如下:
mixed substr_replace ( mixed $string , mixed $replacement , mixed $start [, mixed $length ] )
substr_replace() 在字符串 string 的副本中將由 start 和可選的 length 參數(shù)限定的子字符串使用 replacement 進行替換。
如果 start 為正數(shù),替換將從 string 的 start 位置開始。如果 start 為負數(shù),替換將從 string 的倒數(shù)第 start 個位置開始。
如果設定了 length 參數(shù)并且為正數(shù),就表示 string 中被替換的子字符串的長度。如果設定為負數(shù),就表示待替換的子字符串結尾處距離 string 末端的字符個數(shù)。如果沒有提供此參數(shù),那么默認為 strlen(string)(字符串的長度)。當然,如果 length 為 0,那么這個函數(shù)的功能為將 replacement 插入 string 的 start 位置處。
該函數(shù)的使用示例如下:
以上代碼的執(zhí)行結果為:
hi,world,hello,world
分享標題:PHP字符串替換
分享地址:http://m.5511xx.com/article/dpdehgj.html


咨詢
建站咨詢
