標籤:
<?php$mobile = "15810320826"; echo substr_replace($mobile,‘****‘,3 , 4); ?>
substr_replace
(PHP 4, PHP 5)
substr_replace — 替換字串的子串
說明mixed substr_replace ( mixed
$string , mixed
$replacement , mixed
$start [, mixed
$length ] )
substr_replace() 在字串 string 的副本中將由 start 和可選的 length 參數限定的子字串使用 replacement 進行替換。
參數
-
string
-
輸入字串。
An array of strings can be provided, in which case the replacements will occur on each string in turn. In this case, the replacement,start and length parameters may be provided either as scalar values to be applied to each input string in turn, or as arrays, in which case the corresponding array element will be used for each input string.
-
replacement
-
替換字串。
-
start
-
如果 start 為正數,替換將從 string 的 start 位置開始。
如果 start 為負數,替換將從 string 的倒數第 start 個位置開始。
-
length
-
如果設定了這個參數並且為正數,表示 string 中被替換的子字串的長度。如果設定為負數,它表示待替換的子字串結尾處距離string 末端的字元個數。如果沒有提供此參數,那麼它預設為 strlen( string ) (字串的長度)。當然,如果 length 為 0,那麼這個函數的功能為將 replacement 插入到 string 的 start 位置處。
傳回值
返回結果字串。如果 string 是個數組,那麼也將返回一個數組。
substr_replace()函數:將手機號中間4位隱藏為*號