Home > Backend Development > PHP Tutorial > irreplacable PHP's substr_replace replaces the characters between the specified two positions with symbols

irreplacable PHP's substr_replace replaces the characters between the specified two positions with symbols

WBOY
Release: 2016-07-29 08:45:07
Original
1642 people have browsed it

Copy the code The code is as follows:


$username = "zongzi";
echo substr_replace($username,'**','1','2');


Definition and usage

The substr_replace() function replaces part of a string with another string.

Syntax

substr_replace(string,replacement,start,length)
Copy after login
Parameters Description
string Required. Specifies the string to check.
replacement Required. Specifies the string to be inserted.
start

Required. Specifies where in the string to begin replacement.

  • Positive number - start replacing at offset start
  • Negative number - start replacing at startth offset from the end of the string
  • 0 - Start replacing at the first character in the string
charlist

Optional. Specifies how many characters to replace.

  • Positive number - the length of the string to be replaced
  • Negative number - the number of characters to be replaced starting from the end of the string
  • 0 - insert instead of replace

Tips and Notes

Note: If start is negative and length is less than or equal to start, then length is 0.
Example

Copy code The code is as follows:


echo substr_replace("Hello world","earth",6);
?>


Output:
Hello earth

The above introduces the irreplacable substr_replace of PHP to replace the characters between the specified two positions with numbers, including the irreplacable content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template