Common php string handler functions: 1. character location lookup function:
Strpos ($ str, $ seach, [int]); searches for the first position of search in $ str starting from int;
Stripos ($ str, $ seach, [int]); returns the position where the string first appears in another string. This function is case insensitive.
Strrpos ($ str, search, [int]): searches for the last position of search in $ str starting from int.
Strripos ($ str, search, [int]): Same as above. This function is case insensitive.
2. functions used to extract substrings
Substr ($ str, int start, [int len])
Strstr ($ str1, str2)
The stristr () function is the same as the strstr function, but it is case insensitive.
Strrchr () is returned from the last searched character. usage: get the file name in the path
3. replace the PHP string function of the string
Str_replace (search, replace, source) search replace with replace in source
Str_ireplace (search, replace, $ str): Same as above. This function is case insensitive.
Strtr ($ str, $ from, $ to) this function returns a copy of str and converts the characters specified in from
$ Trans = array ("hello" => "hi", "hi" => "hello ");
Echo strtr ("hi all, I said hello", $ trans );
?>
Substr_replace ($ Str, $ rep, $ start [, length]): $ str original string, $ new string after rep replacement, $ start position, $ length replacement length, optional
4. character length
Int strlen ($ str)
5. Comparison of character functions
Int strcmp ($ str1, $ str2) $ str1 >=< $ str2 is positive 1, 0,-1 respectively (string comparison)
Strcasecmp () ignore case sensitivity (same as above)
Strnatcmp ("8", "18") compares strings in natural order
Strnatcasecmp ()
6. PHP string functions split into arrays
Str_split ($ str, len)
Split (search, $ str, [int])
Explode (search, $ str, [int]) splits $ str by the search character. the returned array int is divided several times, and the following values are not separated.
7. remove spaces:
Ltrim () rtrim () trim ()
8. space function
Chunk_split ($ str, 2) adds a space to the $ str string containing 2 characters;
9. chr and ord -- return the specified character or ascii
10. functions related to HTML code
Nl2br () converts \ n
Strip_tags ($ str ,['
']) Remove HTML and PHP tags
For example, echo strip_tags ($ text ,'
')
Htmlspecialchars ($ str [, var])
11. PHP string functions for case-insensitive character conversion
Strolower (str)
Stroupper (str)
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 PHP string functions
Addslashes (str) converts single quotation marks ('), double quotation marks ("), backslash (\), and NUL strings \',\",\\.
Magic_quotes_gpc = On: automatically escapes get, post, and cookie content.
Get_magic_quotes_gpc (): checks whether magic_quotes_gpc is enabled.
Stripslashes (): removes the backslash from the string.