Four PHP text functions strstr strrchr substr STRISTR

Source: Internet
Author: User
    1. strstr function
    2. $email = ' liruxing1715@sina.com@qq.com ';
    3. $domain = Strstr ($email, ' @ ');
    4. echo "strstr test result: {$domain}
      ";
    5. $domain = Strstr ($email, ' @ ', true);
    6. echo "strstr test result: {$domain}
      ";
    7. /*
    8. The test results are:
    9. STRSTR test Result: @sina. com@qq.com
    10. STRSTR test Result: liruxing1715
    11. */
    12. ?>
Copy Code

Note: If the string you are looking for is not found, then return FALSE. 2, Stristrstristr-function and strstr function, the only difference is that the case is unclear.

3, STRRCHRstrrchr-displays the last found, the string to find, and the following string.

    1. STRRCHR function
    2. $email = ' liruxing1715@sina.com@qq.com ';
    3. $domain = STRRCHR ($email, ' @ ');
    4. echo "STRRCHR test result: {$domain}
      ";
    5. /*
    6. The test results are:
    7. STRRCHR test Result: @qq. com
    8. */
    9. ?>
Copy Code

Note: If the string you are looking for is not found, then return FALSE. 4. substrsubstr-in a string, the character is intercepted according to the given length. Format: String substr (string $string, int $start [, int $length]) parameter description: $string: the string to intercept; $start: The starting position to intercept, starting from 0 by default, if Start is A negative number, the returned string starts at the end of the $string $start character, or FALSE if the length of the string is less than or equal to start. $length: The end position of the intercept, if the first $length is empty, then return from the start position to the end.

    1. substr function
    2. $email = ' liruxing1715@sina.com@qq.com ';
    3. $domain = substr ($email, 10);
    4. echo "substr test result: {$domain}
      ";
    5. $domain = substr ($email, 10, 5);
    6. echo "substr test result: {$domain}
      ";
    7. $domain = substr ($email,-5, 5); The last digit of the string is-1
    8. echo "substr test result: {$domain}
      ";
    9. /*
    10. The test results are:
    11. SUBSTR test Result: 15@sina.com@qq.com
    12. SUBSTR test Result: 15@si
    13. SUBSTR test Result: q.com
    14. */
    15. ?>
Copy Code
  • Related Article

    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.