str_replace
Replaces all occurrences of search string with replacement string.
Parameters
main.php
Return Values
string|array
Returns a string or array with replaced values
On success:String or array with all occurrences of search replaced with replace
On failure:Original subject if search is not found
Notes
- Replacement is case-sensitive, use str_ireplace() for case-insensitive replacement
- Can accept arrays for search and replace parameters for multiple replacements
- Replacements are performed left to right, may replace previously inserted values
- Optional count parameter returns the number of replacements performed
Changelog
- Function has been available since PHP 4.0.0
Related Functions
trim
StringReturns a string with whitespace (or other characters) stripped from the beginning and end of string.
cleanwhitespacesanitize
htmlspecialchars
SecurityConverts special characters to HTML entities to prevent XSS attacks and ensure safe HTML output.
securityxsssanitize
filter_var
ValidationFilters a variable with a specified filter, used for validating and sanitizing data.
validatesanitizesecurity
array_values
ArrayReturns all values from an array with numeric keys, effectively reindexing the array.
valuesreindexclean
strtr
StringTranslates characters or replaces substrings in a string using either character mapping or replacement pairs.
replacetranslatesubstitute
preg_replace
RegExPerforms a regular expression search and replace operation on a string or array of strings.
regexpatternreplace