1.2.1176. Strtr Arguments¶
Strtr() replaces characters by others in a string. When using strings, strtr() replaces characters as long as they have a replacement. All others are ignored.
In particular, strtr() works on strings of the same size, and cannot be used to remove chars.
<?php
$string = 'abcde';
echo strtr($string, 'abc', 'AB');
echo strtr($string, 'ab', 'ABC');
// displays ABcde
// c is ignored each time
// strtr can't remove a char
echo strtr($string, 'a', '');
// displays a
?>
See also strtr.
1.2.1176.1. Suggestions¶
Check the call to strtr() and make sure the arguments are of the same size
Replace strtr() with str_replace(), which works with strings and array, not chars
Replace strtr() with preg_match(), which works with patterns and not chars
1.2.1176.2. Specs¶
Short name |
Php/StrtrArguments |
Rulesets |
|
Exakat since |
1.2.3 |
PHP Version |
All |
Severity |
Major |
Time To Fix |
Instant (5 mins) |
Precision |
Very high |
Examples |
|
Available in |