Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the difference between the efficiency of strtr, str_replace and preg_replace functions

Shulou Source: shulou.com Published: 2022-06-03 06:39:09 11月15日 Update

This article is about the difference between the efficiency of strtr, str_replace and preg_replace functions. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Having analyzed the source code of strtr before, compare the efficiency of strtr, str_replace and preg_replace:

The code is as follows:

$str =

'1111111100000000000000000000000001110000010000010010000010010000010100000010

'

$str = str_repeat ($str, 1)

$pattern1 = array ('12345) = >', '67891 = >')

$pattern2 = array ('averse = >', '1234567890 = >')

$pattern3 ='/ 12345 | 67891 Zero'

$pattern4 ='/ a | 1234567890 Universe'

$pattern5 = array ('12345,' 67891')

$pattern6 = array ('asides,' 1234567890')

$t = microtime (true)

For ($iTun0; $I

Tags: Efficiency character string output subscript length function maximum code that is element content number array time more source code article result order Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia OPPO Reno Shulou Technology Apple MariaDB