Home > Backend Development > PHP Problem > How to replace string from specified position in php

How to replace string from specified position in php

藏色散人
Release: 2023-03-05 16:02:01
Original
4010 people have browsed it

In PHP, you can use the "substr_replace" function to replace a string from a specified position. The syntax is "substr_replace(string,replacement,start,length)". The parameter start means to start replacing from the specified position.

How to replace string from specified position in php

Recommended: "PHP Video Tutorial"

php method to replace characters starting from the specified position

Definition and usage

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

Syntax

substr_replace(string,replacement,start,length)
echo substr_replace("hello world","earth",6);
Copy after login

Parameters

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 numbers - replace at the start offset

Negative numbers - replace at the start offset from the end of the string

0 - replace at the character Start replacing

charlist

from the first character in the string. 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

The above is the detailed content of How to replace string from specified position in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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