Home > Backend Development > PHP Tutorial > How to replace some characters in a custom string in php_PHP Tutorial

How to replace some characters in a custom string in php_PHP Tutorial

WBOY
Release: 2016-07-20 11:02:44
Original
923 people have browsed it

php tutorial How to replace some characters in a custom string

The substr_replace() function replaces some characters in a custom string
Syntax: substr_replace(str,repl,start,[int length])
Grammar description:
str——Required parameter, specify the original string to be operated
repl - specifies the new string after replacement
Start——Specify the starting position of the replacement string
Length——optional parameter, specifies the length of the returned string.
Application example of using substr_replace() function to replace string:

Example code:
$b=”Manual”;
$c=”zero’s php blog”;
echo substr_replace($c,$b,9,4);
?>
Output result:
zero's php manual

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 replacing at start offset
  • Negative numbers - replace 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 from the end of the string
  • 0 - insert instead of replace
http://www.bkjia.com/PHPjc/445348.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445348.htmlTechArticle
php tutorial to replace some characters in a custom string method substr_replace() function to replace some characters in a custom string Syntax for replacing some characters: substr_replace(str,repl,start,[int len...
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