Four php text functions strstrstrrchrsubstrstristr

Source: Internet
Author: User
Four php text functions strstrstrrchrsubstrstristr

  1. // Strstr function
  2. $ Email = 'ruxing1715 @ 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. Test results:
  9. Strstr test result: @ sina.com@qq.com
  10. Strstr test result: liruxing1715
  11. */
  12. ?>

Note: If the string to be searched is not found, FALSE is returned.2. stristrThe stristr-function is the same as the strstr function. The only difference is that the case sensitivity is unknown.

3. strrchrStrrchr-display the last found string and the subsequent string.

  1. // Strrchr function
  2. $ Email = 'ruxing1715 @ sina.com@qq.com ';
  3. $ Domain = strrchr ($ email ,'@');
  4. Echo "strrchr test result: {$ domain}
    ";
  5. /*
  6. Test results:
  7. Strrchr test result: @ qq.com
  8. */
  9. ?>

Note: If the string to be searched is not found, FALSE is returned.4. substrSubstr-in a string, the string is truncated based on the given length. Format: string substr (string $ string, int $ start [, int $ length]) parameter description: $ string: string to be truncated; $ start: start position to be truncated, the default value is start from 0. if start is a negative number, the returned string starts with the $ start character at the end of $ string. if the string length is less than or equal to start, returns FALSE. $ Length: the end position of the truncation. if the value of $ length is null, the return value ranges from the start position to the end.

  1. // Substr function
  2. $ Email = 'ruxing1715 @ 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 character of the string is-1.
  8. Echo "substr test result: {$ domain}
    ";
  9. /*
  10. Test results:
  11. Substr test results: 15@sina.com @ qq.com
  12. Substr test result: 15 @ si
  13. Substr test result: q.com
  14. */
  15. ?>

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.