In the last article, we introduced "Converting php variables to json format data". In this article, we will introduce strings. String is a common data type that is operated during php
. For substring operations, php
has built-in str_replace()
. This article will show you Let’s take a look. First, let's take a look at the syntax of the str_replace()
function.
1 |
|
$search: The target that needs to be searched
$replace: The value that needs to be replaced with the target
$subject: String or array to be processed
$count: Optional, the number of times replacement occurs
Return value: This function returns the replaced array or string.
Code example:
1. The parameters are all strings
1 2 3 4 5 |
|
1 |
|
2. The parameters are all arrays
1 2 3 4 5 |
|
1 |
|
Recommendation: 《2021 Summary of PHP interview questions (Collection)》《php video tutorial》
The above is the detailed content of Detailed explanation of str_replace() substring replacement function. For more information, please follow other related articles on the PHP Chinese website!