Get the App
SLTechnology News&Howtos  ›  Development  › 

How php replaces the third character of a string

Shulou Source: shulou.com Published: 2022-06-02 02:44:46 09月11日 Update

This article is about how php replaces the third character of a string. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

In php, you can use the substr_replace () function to replace the third character of a specified string, which can replace a character of a specified length starting at a specified position in the string; the syntax is "substr_replace (string," replacement value ", 2j 1)".

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In php, you can use the substr_replace () function to replace the third character of a specified string.

Example:

Description:

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

The substr_replace () function can replace characters of a specified length, starting at a specified position in a string.

Syntax:

The substr_replace (string,replacement,start,length) parameter is required to describe string. Specifies the string to check. Replacement is required. Specifies the string to insert. Start is required. Specifies where to start the replacement of the string.

Positive number-starts at the specified position of the string

Negative number-starts at the specified position at the end of the string

0-starts at the first character in the string

Length is optional. Specifies how many characters to replace. The default is the same length as the string.

Positive number-the length of the string being replaced

Negative number-the number of characters replaced from the end of the string

0-insert instead of replace

Return value: returns the string to be replaced. If string is an array, an array is returned.

Thank you for reading! This is the end of this article on "how to replace the third character of a string by php". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Characters strings functions positions length content arrays more positive numbers articles grammars negative numbers good practical same parameters tutorials articles ends environment Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Redmi MariaDB NVidia Shulou Tech Info