str_replace
str_replace — Replace all occurrences of the search string with the replacement string.Description
str_replace( array|string $search, array|string $replace, string|array $subject, int &$count = null ): string|arrayThis function returns a string or an array with all occurrences of search in subject replaced with the given replace value. If you don't need fancy replacing rules (like regular expressions), you should use this function instead of preg_replace().
Parameters
If search and replace are arrays, then str_replace() takes a value from each array and uses them to search and replace on subject. If replace has fewer values than search, then an empty string is used for the rest of replacement values. If search is an array and replace is a string, then this replacement string is used for every value of search. The converse would not make sense, though. If search or replace are arrays, their elements are processed first to last.
search
The value being searched for, otherwise known as the needle. An array may be used to designate multiple needles.
replace
The replacement value that replaces found search values. An array may be used to designate multiple replacements.
subject
The string or array being searched and replaced on, otherwise known as the haystack.
If subject is an array, then the search and replace is performed with every entry of subject, and the return value is an array as well.
count
If passed, this will be set to the number of replacements performed.
Return Values
This function returns a string or an array with the replaced values.More information about str_replace on official PHP documentation site
str_replace - Popular snippets
- PHP 8.2.13 / MySQL 8.0 str_replace var_export
last run:
2024-10-23 21:36:51
20
- PHP 8.1 / MySQL 5.7 base64_decode preg_match_all count str_replace chr hexdec preg_match
last run:
2023-11-12 20:14:19
17
- PHP 7.4 / MySQL 5.7 preg_match str_replace date_default_timezone_set strtotime date round abs
last run:
2023-03-26 14:06:36
13
- PHP 7.4 / MySQL 5.7 is_file file_get_contents str_replace file_put_contents
last run:
2024-07-29 21:48:48
9
- PHP 8.1 / MySQL 5.7 json_decode preg_match array_filter var_dump str_replace
last run:
2023-08-30 06:27:32
8
- PHP 8.1 / MySQL 5.7 print_r str_replace microtime time
last run:
2024-07-27 21:41:05
7
- PHP 8.0 / MySQL 8.0 str_replace preg_match
last run:
2023-11-17 10:49:53
7
- PHP 8.1 / MySQL 5.7 preg_match_all str_replace print_r
last run:
2023-09-15 12:31:34
7
- PHP 8.1 / MySQL 5.7 preg_match_all str_replace print_r
last run:
2023-09-15 12:30:55
7
- PHP 8.1 / MySQL 5.7 base64_decode preg_match_all count str_replace chr hexdec preg_match
last run:
2023-07-14 22:57:26
7
str_replace - New snippets
-
PHP 8.2.13 / MySQL 8.0 str_replace var_export
added at:
2024-10-23 21:41:03
1
-
PHP 8.2.13 / MySQL 8.0 str_replace var_export
added at:
2024-10-23 21:38:57
1
-
PHP 8.2.13 / MySQL 8.0 str_replace var_export
added at:
2024-10-23 21:37:29
1
-
PHP 8.2.13 / MySQL 8.0 str_replace var_export
added at:
2024-09-16 13:57:51
1
-
PHP 8.2.13 / MySQL 8.0 str_replace var_export
added at:
2024-09-16 13:57:29
1
-
PHP 8.2.13 / MySQL 8.0 str_replace var_export
added at:
2024-09-16 13:57:19
1
-
PHP 8.1 / MySQL 5.7 str_split chr ord count str_replace base64_decode
added at:
2024-08-19 08:41:40
1
-
PHP 8.2.13 / MySQL 8.0 str_replace var_export
added at:
2024-08-19 01:29:37
2
-
PHP 8.2.13 / MySQL 5.7 str_replace
added at:
2024-08-10 17:45:24
1
-
PHP 8.2.13 / MySQL 5.7 str_replace
added at:
2024-08-10 17:44:57
1