PHP substr and explode selection on split string

Source: Internet
Author: User
Tags explode

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.