Fastest way to replace string in PHP

I need to replace some line in PHP code so that it looks better. What would be the best way to do this?

+5
source share
4 answers

The usual suspects are str_replaceand preg_replace.

+8
source
preg_replace

This is a good way to go and use regular expressions so that you have the flexibility to do this.

0
source

(, - , ), sed .

man sed
0

It depends. If str_replace works for your case, I think it's faster and less memory consumer than preg_replace

0
source

All Articles