新聞中心
本教程操作環(huán)境:windows7系統(tǒng)、php7.1版、DELL G3電腦

10年專注成都網(wǎng)站制作,成都企業(yè)網(wǎng)站定制,個人網(wǎng)站制作服務,為大家分享網(wǎng)站制作知識、方案,網(wǎng)站設計流程、步驟,成功服務上千家企業(yè)。為您提供網(wǎng)站建設,網(wǎng)站制作,網(wǎng)頁設計及定制高端網(wǎng)站建設服務,專注于成都企業(yè)網(wǎng)站定制,高端網(wǎng)頁制作,對成都木屋等多個方面,擁有多年的網(wǎng)站運維經(jīng)驗。
php替換指定第幾位字符串
在php中,可以使用substr_replace()函數(shù)來替換字符串中指定位置的字符。
"; echo substr_replace($str, "B", 1,1)."
"; echo substr_replace($str, "C", 2,1)."
"; echo substr_replace($str, "D", 3,1)."
"; echo substr_replace($str, "E", 4,1)."
"; echo substr_replace($str, "F", 5,1)."
"; ?>
說明:
substr_replace() 函數(shù)把字符串的一部分替換為另一個字符串。
語法:
substr_replace($string,$replacement,$start,$length)
| 參數(shù) | 描述 |
|---|---|
| string | 必需。規(guī)定要檢查的字符串。 |
| replacement | 必需。規(guī)定要插入的字符串。 |
| start | 必需。規(guī)定在字符串的何處開始替換。
|
| length | 可選。規(guī)定要替換多少個字符。默認是與字符串長度相同。
|
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 位置處。
"; echo substr_replace($str, $replace, -1,1)."
"; ?>
標題名稱:php怎么替換指定第幾位字符串
文章起源:http://www.5511xx.com/article/djjhphe.html


咨詢
建站咨詢
