Strings are a commonly used type in php. Replacement of strings is not as convenient as arrays. So how to replace characters in a string? This article will explain Let’s take a look at how to use thestr_repalce()
function. First, let’s take a look at the syntax of the function:
str_replace ( mixed $search , mixed $replace , mixed $subject , int $count = ? )
$search: search Target value, multiple targets can be specified.
#$replace: the replacement value of search.
$subject: Array or string to perform replacement
$count: Optional, if specified, its value will be set is the number of times replacement occurs.
Return value: This function returns the replaced array or string.
Code example:
1. There are three required parameters
输出:ok hehe great,that hehe php.cn
2. There are four parameters
"."总共替换了:".$count; ?>
输出:ok hehe great,that hehe php.cn 总共替换了:2
Recommended:《2021 PHP Summary of interview questions (collection)》《php video tutorial》
The above is the detailed content of Detailed explanation of str_replace() in php (with code examples). For more information, please follow other related articles on the PHP Chinese website!