substr_replace() function in PHP
The substr_replace() function is used to replace part of a string with another string.
Syntax
substr_replace(str,replacement,begin,len)
Parameters
str - The string to check
< strong>replacement - The string to be inserted
begin - The position where the replacement begins -
If begin is a positive number: start replacing from the specified position in the string
If begin is n number: - start replacing at the specified position from the end of the string
If begin is 0 - start replacing from the first character in the string.
len - The number of characters to replace. Defaults to the same length as the string.
If len is a positive number - the length of the string to be replaced
If len is a negative number - how much should be left at the end of the string after replacement characters
If len is 0 - insert instead of replace. < /p>
Return
substr_replace() function returns the replaced string.
Example h2>
The following is an example-
Live demonstration
<?php echo substr_replace("Demo text","word",5); ?>
Output
The following is the output-
Demo word
Example
Let's see another example, replace string from end of string -
Live Demonstration
<?php echo substr_replace("Demo text","word",-5); ?>
Output
Here is the output-
Demoword
The above is the detailed content of substr_replace() function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In PHP program development, sometimes text content needs to be processed, including replacing the Enter key. Below we will briefly introduce how to replace the Enter key in PHP.

PHP regular expressions are a powerful tool for text processing and conversion. It can effectively manage text information by parsing text content and replacing or intercepting it according to specific patterns. Among them, a common application of regular expressions is to replace strings starting with specific characters. We will explain this as follows

With the continuous development of the Internet, PHP's application scenarios are becoming more and more extensive. In PHP development, sometimes you need to replace special characters in a string. In this case, you can use regular expressions for replacement. This article will introduce how to use regular expressions to replace special characters in strings in PHP. First, learn the basics of regular expressions. Regular expressions are a language used to describe patterns in some strings. Regular expressions include some special characters, such as ., *, +, ?, etc. These special characters have special meanings. in PH

PHP is a widely used scripting language that can be used to develop various web applications and websites. In these applications, strings are an integral part. In many cases, we need to perform operations such as replacing, splitting or intercepting strings. This article will explain how to replace a string from the left in PHP.

PHP is a scripting language widely used in website development and has powerful string processing capabilities. During string processing, sometimes you need to replace multiple texts in the string. In this case, you can use PHP's substr_replace() function to achieve this. The substr_replace() function is used to replace the specified substring in a string and return the replaced string. Its syntax is as follows: stringsubstr_replace(string$str

preg_replace() function in PHP: How to replace a string using regular expressions, specific code examples are needed In PHP, the preg_replace() function is a very powerful and flexible function that allows us to search and replace characters using regular expressions string. Whether it is to remove specific characters from a string or replace text in a specific format, the preg_replace() function can help us achieve it easily. First, let's take a look at preg_replace()

Replacing strings is one of the most basic operations in PHP. The replacement function is crucial in data processing and string operations, and can improve program execution efficiency and performance. There are many functions for replacing strings in PHP, such as: substr_replace, str_replace, preg_replace and so on. But for specific string replacements, special replacement rules may need to be used. In this article, we will learn how to replace the 11 digits after the colon.

Use the strings.Replace function to replace substrings in a string and set the number of replacements. In the Go language, we can use the strings.Replace function to replace substrings in a string. The signature of this function is as follows: funcReplace(s,old,newstring,nint)string where s represents the original string, old represents the substring to be replaced, new represents the replaced substring, and n represents the number of times to replace. Pass below
