First, explode
$str = ' Data:image/png;base64,ivborw0kggoaaaansuheugaaalcaaaeccaiaaabc8mukaaag ... '; $TMPARR Explode $str ); $a $TMPARR [0]; $b $TMPARR [1];
Where the OP number is 11 and 7 different functions are used to perform the operation
Second, Substr+strpos
$str = ' Data:image/png;base64,ivborw0kggoaaaansuheugaaalcaaaeccaiaaabc8mukaaag ... '; $a substr ($strstrpos($str, ', ')); $b substr ($strstrpos($str, ', '));
Where the OP number is 21 and 6 different functions are used to perform the operation
Third, analysis
1, Substr+strpos call function is 1 less than explode.
2, the Substr+strpos 3, 4 lines each call 10 functions, that is, if only get the beginning or end of the string, Substr+strpos and explode call the function of the same number of times.
3, if the string has a fixed beginning or end, you can not use methods such as Strpos to determine the character position, then its opcode layer is what?
Again, the code analysis is changed, as follows:
$str = ' Data:image/png;base64,ivborw0kggoaaaansuheugaaalcaaaeccaiaaabc8mukaaag ... '; $a substr ($str, 0, 20);
At this point, the OP number is 8, and the operation is performed using 6 different functions.
The reduction of the OP number is expected, but the function used is not reduced, and obviously the function used by Strpos is coincident with substr!
Iv. Conclusion
1. Substr+strpos is preferred when getting the beginning or end of a string.
2. When getting a fixed start or end, use substr and specify the start or length.
3, when the string split out the fragment is greater than 1 o'clock, explode optimal!
PHP substr and explode selection on split string