Home  >  Article  >  Backend Development  >  PHP's substr_replace replaces the characters between the specified two positions with *_PHP tutorial

PHP's substr_replace replaces the characters between the specified two positions with *_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:30:30922browse

Copy 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.

Grammar

substr_replace(string,replacement,start,length)
Parameters Description
string Required. Specifies the string to check.
replacement Required. Specifies the string to be inserted.
start
参数 描述
string 必需。规定要检查的字符串。
replacement 必需。规定要插入的字符串。
start

必需。规定在字符串的何处开始替换。

  • 正数 - 在第 start 个偏移量开始替换
  • 负数 - 在从字符串结尾的第 start 个偏移量开始替换
  • 0 - 在字符串中的第一个字符处开始替换
charlist

可选。规定要替换多少个字符。

  • 正数 - 被替换的字符串长度
  • 负数 - 从字符串末端开始的被替换字符数
  • 0 - 插入而非替换
Required. Specifies where in the string to begin replacement.
  • Positive number - start replacement at offset
    start

  • Negative numbers - start replacing at start

    offset from the end of the string

  • 0 - Start replacement 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);

?>

Hello earth http://www.bkjia.com/PHPjc/323206.htmlwww.bkjia.comtrue
http: //www.bkjia.com/PHPjc/323206.html
TechArticle
Copy the code as follows: $username = "zongzi"; echo substr_replace($username,'**',' 1','2'); Definition and usage substr_replace() function replaces part of a string with another string...
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