strtr
Translates characters or replaces substrings in a string using either character mapping or replacement pairs.
Parameters
main.php
Return Values
string
Returns the translated string with characters/substrings replaced
On success:String with all specified characters or substrings translated
On failure:Original string if no matches found, false if empty key in array
Notes
- With 3 parameters: translates individual characters from $from to $to
- With 2 parameters (array): replaces substrings based on key => value pairs
- Array version processes longer keys first, avoiding partial replacements
- Case-sensitive replacement - use array version for case-insensitive needs
Changelog
- 4.0.0: Function available since this version
- 8.0.0: Empty string keys in array parameter now raise E_WARNING
Related Functions
str_replace
StringReplaces all occurrences of search string with replacement string.
replacesanitizeclean
preg_replace
RegExPerforms a regular expression search and replace operation on a string or array of strings.
regexpatternreplace