Project

General

Profile

Actions

Task #54500

closed

Use arrays in str_replace() calls

Added by Michiel Roos over 10 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Performance
Target version:
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

Also available in: Atom PDF