Actions
Task #54500
closedUse arrays in str_replace() calls
Start date:
2013-12-18
Due date:
% Done:
100%
Estimated time:
TYPO3 Version:
6.2
PHP Version:
5.3
Tags:
Complexity:
easy
Sprint Focus:
Description
Multiple consecutive calls to str_replace can be replaced with a single call if the subject is the same.
This will speed up the replacement and in some cases has the benefit of being able to return or use the result of the str_replace directly without creating an intermediate variable.
Bad:
$lala = 'something';
$lala = str_replace('so', 'the', $lala);
$lala = str_replace('me', ' ', $lala);
$lala = str_replace('thing', 'other', $lala);
Good:
$lala = str_replace(
array('so', 'me', 'thing'),
array('the', ' ', 'other'),
'something'
);
Actions