A collection of built-in string operation functions in PHP and a collection of php string functions

Source: Internet
Author: User

A collection of built-in string operation functions in PHP and a collection of php string functions
1. Search for the character location function:

Strpos ($ str, search, [int]): // search for the first position of search in $ str starting from int; strrpos ($ str, search, [int]): // search for the last occurrence position of search in $ str starting from int

2. Extract sub-character functions (dual-byte)
Submit ($ str, int start [, int length]): // extract a [length string] starting from the strat position in $ str. Strstr ($ str1, $ str2): // search $ str2 from $ str1 (the first position) and extract the string from it to the end. If not, FALSE is returned. Stristr () // The function is the same as that of strstr, but it is case insensitive. Strrchr () // returns from the last searched character. Usage: get the file name in the path

3. Replace string
Str_replace (search, replace, $ str): from $ str, search for search to replace str_irreplace (search, replace, $ str): strtr ($ str, search, replace ): in this function, replace cannot be ""; substr_replace ($ Str, $ rep, $ start [, length]) $ str original string, $ rep new string after replacement, the starting position of $ start and the length of $ length. This parameter is optional.
4. query string length
int strlen($str)

5. Comparison of character Functions
Int strcmp ($ str1, $ str2): $ str1 >=< $ str2 is positive 1, 0,-1 respectively (string comparison
Strcasecmp () Same as above (case-insensitive
Strnatcmp ("4", "14") compares strings in natural order
Strnatcasecmp () is the same as above (case sensitive)


6. Split into array Functions
Str_split ($ str, len): splits $ str by len Length and returns an array.
Split (search, $ str [, int]): splits $ str by the search character and returns the number of times the array int is split.
Explode (search, $ str [, int])
7. Remove spaces:
ltrim、rtrim、trim
8. Space Function
Chunk_split ($ str, 2); add a space to the $ str string containing 2 characters;
9. Return the specified character or ascii
chr、ord

 

10. functions related to HTML code
Nl2br (): converts \ n to <br>.
Strip_tags ($ str [, '<p>']): // remove HTML and PHP tags
Htmlspecialchars ($ str [, parameter]): // the HTML code parameters output normally on the page are converted.
11. case-insensitive conversion functions
Strtolower ($ str) string to lowercase
Strtoupper ($ str) string to uppercase
Ucfirst ($ str) converts the first character of the function to uppercase.
Ucwords ($ str) converts the first letter of each word to uppercase
12. Database-related functions
Addslashes ($ str): converts single quotation marks ('), double quotation marks ("), backslash (\), and NUL strings \',\",\\.
Magic_quotes_gpc = On automatically escapes the get post cookie content
Get_magic_quotes_gpc () Check whether magic_quotes_gpc is enabled
Stripslashes () removes the backslash from the string
13. Connection Functions
Implode (str, $ arr) concatenates a string array into a string based on specified characters;
The implode () function has an alias function join.
 

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.