Comparison between PHP strtr and Str_replace
Functions have the ability to replace characters. But the STRTR is 4 times times more than the str_replace performance. Specific circumstances, please
Look at the following decomposition:
The first is the STRTR function:
Example 1: When
The following are the referenced contents:
<?php
This time the output is Baicai rather than Bai123cai, because str ("Pao") <strlen ("bai123")
Echo strtr ("paocai!", "Pao", "bai123");
?>
Instance 2: When the replaced value is less than the replacement target
The following are the referenced contents:
<?php
This time the output is Laocai rather than Lacai, because str ("Pao") >strlen ("La")
Echo strtr ("paocai!", "Pao", "la");
?>
Example 3: Array substitution support
The following are the referenced contents:
<?php
$Arr =array (' ao ' => ' oa ', ' ai ' => ' ia ');
Echo strtr ("paocai!", $ARR); This time the output is Poacia
?>
The second is str_replace:
The following are the referenced contents:
<?php
Echo str_replace ("You", "Paocai", "I Love you!"); Will output I love paocai!
?>
Summary: STRTR He is related to the length of the character, but Str_replace is not related, estimated in the running step
Will read the string length so it is much slower than STRTR.