Home >Backend Development >PHP Tutorial >PHP string replacement

PHP string replacement

不言
不言Original
2018-04-13 17:43:493361browse

This article introduces PHP string replacement. Now I share it with everyone. Friends in need can refer to it

substr_replace(string,replacement,start,length)

The first parameter is: the string to be replaced (required)

The second parameter is: the string to be replaced (required)

The third parameter is: the position to start replacing (required)

Positive number - start replacing negative number at the specified position in the string
- Replace

starting at the specified position from the end of the string. - Replace

starting at the first character in the string. The fourth parameter: specifies how many characters to replace. Characters (optional)

Positive number - the length of the string to be replaced
Negative number - indicates the number of characters from the end of the string to the end of the substring to be replaced.

0 - Insert rather than replace


Example:

$str = '220282198801011234';
$new_str = substr_replace($str,'********',6,8);
print_r($new_str);


Print as follows :

220282******1234

The above is the detailed content of PHP string replacement. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn