Home >Backend Development >PHP Tutorial >How to implement string replacement in PHP

How to implement string replacement in PHP

零到壹度
零到壹度Original
2018-04-12 10:34:013509browse

The content of this article is to share with you how to implement string replacement in PHP. It has certain reference value. 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 specification to be replaced The string after (required)

The third parameter is: the starting position of replacement (required)

Positive number - in Replace
at the specified position in the string. Negative numbers - Replace

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

# at the first character in the string. ##The fourth parameter: specifies how many characters to replace (

optional)

Positive number - the length of the string to be replaced

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

0 - Insert rather than replace


Example:

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

Print as follows:

220282* *****1234

Related recommendations:

Detailed explanation of several string replacement functions in php

In php replacement string The first string [no repeated replacement]

php: Commonly used string related functions

The above is the detailed content of How to implement string replacement in PHP. 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