Home > Article > Backend Development > Summary of some commonly used string functions in PHP_PHP tutorial
1. AddcSlashes adds backslash to string
Syntax: string addcslashes(string str,string charlist);
2. AddSlashes adds backslash to string
Syntax: string addslashes(string str);
Add backslash before specific characters: ', ",, NULL
3. bin2hex Convert binary to hexadecimal
Syntax: string bin2hex (string str);
4. Chop removes consecutive blanks, the same as rtrim()
Syntax: string chop(string str);
5. Chr Chr returns the character Syntax: string chr(int ascii);
6. chunk_split Divide the string into small segments
Syntax: string chunk_split(string string,int [chunklen],string [end]);
7. convert_cyr_string string internal code conversion
Syntax: string convert_cyr_string(string str, string from, string to);
8. count_chars returns string information
Syntax: mixed count_chars (string string,[mode]);
9. crypt returns a string encrypted with DES encoding
Syntax: string crypt(string str,string [salt]);
10. echo display content
Syntax: echo(string arg1,string [argn].....);
11. explode split string
Syntax: array explode(string separator,string string ; >Syntax: string get_html_translation_table(int table);
14. get_meta_tags extracts all meta-tagged data from the file
Syntax: array get_meta_tags(string filename,int [use_include_path])
15. htmlentities Convert all characters into HTML string
Syntax: string htmlentities(string string);
16. htmlspecialchars Convert special characters into HTML format
Syntax: string htmlspecialchars(string string);
17. implode turns the array into a string
Syntax: string implode(string glue,array pieces);
18. join turns the array into a string
Syntax: string join(string glue,array,pieces);
19. ltrim removes consecutive blanks
Syntax: string ltrim(string str);
20. md5 uses MD5 pair String processing
syntax: string md5(string str);
21. Metaphone returns the pronunciation value of the string
syntax: string metaphome(string str);
22. nl2br Convert newline characters to
Syntax: string nl2br(string string);
23. Ord Get the ASCII code value of the character
Syntax: int ord(string string);
24. parse_str(string str);
Syntax: vid parse_str(string str)
25. print output string
Syntax: print(string arg);
26. printf outputs formatted string
Syntax: int printf(string format,mixed [args]...);
27. quoted_printable_decode converts qp encoded string into octal string
28. QuoteMeta Add a backslash before special characters
29. rawurldecode decodes a URL-encoded string
Syntax: string rawurldecode(string str);
30. rawurlencode encodes the string into a URL-specific format
31. setlocale sets local information
Syntax: string setlocale(string category, string locale);
32. similar_text counts characters String similarity
Syntax: int similar_text(string first, string second, double [percent]);
33. soundex returns the pronunciation value of the string
Syntax: string soundex(string str);
34. sprintf formats the string
Syntax: string sprintf(string format,mixed [args]...);
35. strcasecmp is case-insensitive in binary mode String comparison
Syntax: int strcasecmp(string str1, string st2);
36. strchr Find the first appearing character
Syntax: string strchr(string haystack, string needle);
37. strcmp String comparison in case-sensitive binary mode
Syntax: int strcmp(string str1, string str2);
38. strcspn The length of different strings
Syntax: int strcspn(string str1,string st2);
39. strip_tags removes HTML and PHP tags
Syntax: string strip_tags(string str,string [allowable_tags]);
40. stripcslashes removes backslash characters
Syntax: string stripcslashes(string str);
41. stripslashes removes backslash characters
Syntax: string stripslashes(string str);
42. stristr returns the content of a string after it appears in another string
Syntax: string stristr(string haystack, string needle);
43. strlen gets the length of the string
44. strpos gets the position where a certain character first appears in the string
Syntax: int strpos(string haystack,string needle,int [offset]);
45. strrchr gets a certain character String
starting from the last occurrence of the character Syntax: string strrchr(string haystack,string needle);
46. str_repet Repeats a string
Syntax: str_repeat(string input,int multiplier);
47. strrev reverses the string
Syntax: string strrev(string string);
48. strrpos Finds the last position of a character in the string
Syntax: int strrpos (string haystack,char needle);
49. strspn counts the number of occurrences of a string in another string
Syntax: int strspn(string str1,string str2);
50. strstr returns the content after a string appears in another string
Syntax: string strstr(string haystack, string needle);
51. strtok cuts the string
Syntax: string strtok(string arg1, string arg2);
Using the string arg2 as the delimiter, multiple delimiters can be put into the strings arg1 and arg2.
52. strtolower Convert all strings to lowercase
Syntax: string strtolower(string str);
53. strtoupper Convert all strings to uppercase
Syntax: string strtoupper( string str);
54. str_replace String replacement
Syntax: str_replace(string needle,string str,string haystack);
Replace all string str in string haystack with needle. This function can be replaced by ereg_replace().
55. strtr string replacement
Grammar: string strtr (string str, string from, string to);
character replacement, replace the from character in the string str one by one is the character in to. If the number of characters from from and to is different, the extra characters will be ignored. The replacement of this function is character, not word or string replacement.
56. substr takes part of the string
syntax: string substr(string string, int start, int [length]);
57. substr_replace string replacement
syntax: string substr_replace(string string, string replacement, int start, int [length]);
Extract a string from string and replace it with string replacement. The definition and use of parameters start and length are the same as subxstr.
58. trim truncates the spaces at the beginning and end of the string
Syntax: string trim(string str);
59. ucfirst changes the first character of the string to uppercase
Syntax: string ucfirst(string str);
60. ucwords Capitalize the first letter of each word in the string
Syntax: string ucwords(string str);