Php string lookup function (strrpos and strchr)

Source: Internet
Author: User
Php string lookup function (strrpos and strchr)

  1. $ Str = '000000 ';
  2. $ Needle = '20140901 ';
  3. $ Result = strchr ($ str, $ needle );
  4. Var_dump ($ result );

Result: string '20140901' (length = 9)

Strrpos searches for the last occurrence of a character in the string. Syntax: int strrpos (string haystack, char needle );

This function is used to find the final position of the character needle in the haystack string. Note that the needle can only be one character, and it is not suitable for Chinese characters. If the specified character is not found, false is returned.

Strpos searches for the first occurrence of a character in a string.

Syntax: int strpos (string haystack, string needle, int [offset]);

This function is used to find the first position where the character needle in the haystack string appears. Note that the needle can only be one character, and it is not suitable for Chinese characters. If the specified character is not found, false is returned. The offset parameter can be omitted, which is used to start searching from offset.

Strspn identifies the number of masks that a string falls on another string.

Syntax: int strspn (string str1, string str2 );

This function uses the str2 string as the mask and can be used to calculate the number of characters in the str1 string that fall into the str2 mask. Php string comparison and search methods detailed description php comparison string similarity function usage reference PHP string comparison function strcmp () and strcasecmp () usage introduction php comparison string similarity instance code

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.