PHP string built-in function summary

Source: Internet
Author: User
1.STRCMP ($str 1, $str 2) If equal returns 0, $str 1> $str 2 returns 1, $STR 1< $str 2 Returns-1 (this is greater than and less than just the position of the comparison, according to the ASCII code table).

2.STRNCMP ($str 1, $str 2, $length) intercept $str1 and $STR2 respectively from a string of 0-length $length, and the output is the same as the first example.

3.strstr ($STR, $need, bool $return _before=false) An important string lookup function is equivalent to STRCHR (), a string that $str operation, $need the string to find, $return _before Whether to return the string $need before $str, the return value of this function is the first occurrence of the $need string in $str to the last position of the $str.

4.STRRCHR ($str, $need) $need The last occurrence of the position to the end of the $str in the string $str

5. $strpos ($STR, $need) The first occurrence of the $need position in the $str, where $str is not found returns NULL, case-insensitive stripos ()

6.strrpos ($str, $need) The location of the last occurrence of $need in $str, no return null found, case insensitive can be strripos ()

7.STRPBRK ($str, $charlist) $str the string to manipulate, $charlist the character set ($charlist = ' ABCDE '), and find any character in the $charlist in $str, Returns the remainder of the beginning of the position where the first occurrence of the specified character

8.substr ($str, $start, $length) an important string intercept function that intercepts a string in the $start position at the beginning of $length in $str

9.explode ($delimiter, $str, $limit =null) string-splitting function, $delimiter as a delimiter, $str as an operator, delimiter cannot be empty, NULL returns FALSE, and an array is returned by default.

10.implode ($glue, array $pieces) an important string connection function that $pieces each element in the array to create a new string return with the connector $gule, equivalent to the join () function.

11.str_split ($STR, $length) splits the $STR and returns the array according to the length specified by $length, noting that Mb_split () can be better compatible with Chinese.

12.str_replace ($search, $replace, $str) Important string substitution functions, $search in $STR are replaced with $replace.

13.substr_replace ($str, $replacement, $start, $length =null) substring substitution function, $str a substring of $length length from the beginning of the $start is replaced with $replacement.

14.str_repeat ($STR, $times) generates a new string and returns $STR repeating $times times

15.str_pad ($str, $pad _length, $pad _str, $pad _type) string fill function, $str the manipulated string, $pad _length the length to fill, $pad _str the string to fill, $pad _ Type:str_pad_left, and so on, indicates where the string is populated.

16.ord (String $char) returns the ASCII corresponding code value chr (int $ascii) returns the ASCII code value corresponding to the string

17.strrev ($STR) string inversion

18.strip_tags ($str, $remain _tags), delete HTML or XML tags as long as <> will be filtered out, you can $remain_tags set the label you want to keep

19.NL2BR ($STR) adding </br> wrapping in front of a new line

Add: The Characters of MB (multibyte) Chinese or some other text are made up of multiple bytes, and the previous function of string splitting and so on does not start with a single byte, which will result in a non-conforming operation for Chinese characters. So mbstring provides a good way to operate.

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.