String Matching and searching

Source: Internet
Author: User

String Matching and search for 1.int preg_match (string $ pattern, string $ subject [, array $ matches [, int $ flags]) search for the content that matches the regular expression given by pattern in the subject string. If matches is provided, it is filled with the search results. $ Matches [0] will contain the text that matches the entire pattern, $ matches [1] will contain the text that matches the child pattern in the first captured bracket, and so on. Flags can be the following flag: PREG_OFFSET_CAPTURE if this flag is set, the offset of the affiliated string is also returned for each matching result. Note that this changes the value of the returned array, so that each unit is also an array. The first item is the matching string, and the second item is its offset. This tag is available from PHP 4.3.0. The flags parameter is available since PHP 4.3.0. Preg_match () returns the number of times pattern matches. Either 0 (no match) or 1 time, because preg_match () will stop searching after the first match. Preg_match_all () indicates that, on the contrary, the end of the subject is always searched. If an error occurs in preg_match (), FALSE is returned. 2. int preg_match_all (string pattern, string subject, array matches [, int flags]) 3. array preg_grep (string pattern, array input) preg_grep () returns an array, including the units in the input array that match the given pattern. 4. string strstr (string $ haystack, mixed $ needle [, bool $ before_needle = false]) returns the haystack string from the position where the needle first appeared to the end of the haystack. Note: If needle is not a string, it is converted to an integer and considered as a sequential value of characters. If before_needle is TRUE, strstr () returns the part before the position of needle in the haystack. This function is case sensitive. If you want to be case insensitive, use stristr (). 5. strpos-locate the first occurrence of a string int strpos (string $ haystack, mixed $ needle [, int $ offset = 0]) // locate the position where the string appears for the first time. If needle is not a string, it is converted to an integer and considered as the sequential value of the character. The optional offset parameter can be used to specify which character in haystack to start searching. The returned numeric position is relative to the starting position of the haystack. 6. strrpos-calculate the position of the last occurrence of the specified string in the target string. Description: int strrpos (string $ haystack, string $ needle [, int $ offset = 0]) 7. substr-Description of the substring of the returned string substr (string $ string, int $ start [, int $ length]) length if a positive length is provided, the returned string can contain a maximum of length characters (depending on the length of the string) starting from start ). If a negative length is provided, many characters at the end of the string will be missed (if start is a negative number, it will be counted from the end of the string ). If start is not in this text, an empty string is returned. If the length is 0, FALSE, or NULL, an empty string is returned. If length is not provided, the returned substring starts from the start position until the end of the string. $ Rest = substr ("abcdef", 0,-1); // return "abcde" $ rest = substr ("abcdef", 2,-1 ); // return "cde" $ rest = substr ("abcdef", 4,-4); // return "" $ rest = substr ("abcdef",-3, -1); // return "de"


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.