PHP substr_replace() 函數(shù)
定義和用法
substr_replace() 函數(shù)把字符串的一部分替換為另一個字符串。
語法
substr_replace(string,replacement,start,length)
參數(shù) | 描述 |
---|---|
string | 必需。規(guī)定要檢查的字符串。 |
replacement | 必需。規(guī)定要插入的字符串。 |
start |
必需。規(guī)定在字符串的何處開始替換。
|
charlist |
可選。規(guī)定要替換多少個字符。
|
提示和注釋
注釋:如果 start 是負數(shù)且 length 小于等于 start,則 length 為 0。
例子
<?php
echo substr_replace("Hello world","earth",6)
;
?>
輸出:
Hello earth