Summary of some common PHP string functions

Source: Internet
Author: User
Tags chop crypt echo display strtok

1. Add the AddcSlashes string to the backslash
Syntax: string addcslashes (string str, string charlist );

2. Add the AddSlashes string to the backslash
Syntax: string addslashes (string str );
Add a backslash ('), ", \, or NULL before a specific character.

3. bin2hex converts binary to hexadecimal.
Syntax: string bin2hex (string str );

4. Remove consecutive gaps with Chop, same as rtrim ()
Syntax: string chop (string str );

5. Chr returns Characters Based on ASCII values
Syntax: string chr (int ascii );

6. chunk_split splits strings into small segments.
Syntax: string chunk_split (string, int [chunklen], string [end]);

7. convert_cyr_string string Internal Code Conversion
Syntax: string convert_cyr_string (string str, string from, string );

8. count_chars returns the string information.
Syntax: mixed count_chars (string, [mode]);

9. The return string of crypt is encrypted by DES.
Syntax: string crypt (string str, string [salt]);

10. echo display content
Syntax: echo (string arg1, string [argn] ......);

11. explode cut string
Syntax: array explode (string separator, string );

12. flush clear the output buffer
Syntax: oid flush (void );

13. get_html_translation_table returns the character conversion table of the htmlspecialchars () and htmlentites () functions.
Syntax: string get_html_translation_table (int table );

14. get_meta_tags extracts all meta-labeled materials from the file.
Syntax: array get_meta_tags (string filename, int [use_include_path])

15. htmlentities convert all the tokens to the HTML string
Syntax: string htmlentities (string );

16. htmlspecialchars converts special characters into HTML Format
Syntax: string htmlspecialchars (string );

17. implode converts the array into a string
Syntax: string implode (string glue, array pieces );

18. join converts an array to a string.
Syntax: string join (string glue, array, pieces );

19. ltrim removes consecutive gaps
Syntax: string ltrim (string str );

20. md5 uses MD5 to process strings
Syntax: string md5 (string str );

21. Metaphone returns the pronunciation of the string.
Syntax: string metaphome (string str );

22. The nl2br converts the line feed character

Syntax: string nl2br (string );

23. Ord obtains the ASCII value of a character.
Syntax: int ord (string );

24. parse_str (string str );
Syntax: vid parse_str (string str)

25. print Output string
Syntax: print (string arg );

26. printf outputs formatted strings
Syntax: int printf (string format, mixed [args]...);

27. quoted_printable_decode converts the qp encoded string to an 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 a string into a URL-specific format.

31. setlocale sets local information
Syntax: string setlocale (string category, string locale );

32. String similarity calculation using similar_text
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 format the string
Syntax: string sprintf (string format, mixed [args]...);

35. strcasecmp is case-insensitive for binary string comparison
Syntax: int strcasecmp (string str1, string st2 );

36. Search for the first character in strchr
Syntax: string strchr (string haystack, string needle );

37. strcmp case-sensitive binary string comparison
Syntax: int strcmp (string str1, string str2 );

38. Length of different strcspns
Syntax: int strcspn (string str1, string st2 );

39. Remove the HTML and PHP tags from strip_tags.
Syntax: string strip_tags (string str, string [allowable_tags]);

40. stripcslashes deletes the backslash string
Syntax: string stripcslashes (string str );

41. stripslashes Delete backslash characters
Syntax: string stripslashes (string str );

42. stristr returns the content after a string appears in another string.
Syntax: string stristr (string haystack, string needle );

43. strlen get the string length

44. strpos obtains the first position of a character in the string.
Syntax: int strpos (string haystack, string needle, int [offset]);

45. strrchr gets the string starting from the last occurrence of a character
Syntax: string strrchr (string haystack, string needle );

46. str_repet repeat a string
Syntax: str_repeat (string input, int multiplier );

47. strrev reverse string
Syntax: string strrev (string );

48. strrpos: Find the final position of a character in the string
Syntax: int strrpos (string haystack, char needle );

49. Calculate the number of occurrences of one string in another string using strspns.
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 cut string
Syntax: string strtok (string arg1, string arg2 );
Take the string arg2 as the separator. Multiple delimiters can be placed in the cut string arg1 and arg2.

52. Convert all strtolower strings to lowercase letters
Syntax: string strtolower (string str );

53. Convert all strtoupper strings into uppercase letters
Syntax: string strtoupper (string str );

54. str_replace string replacement
Syntax: str_replace (string needle, string str, string haystack );
Replace all str strings with needle in the string haystack. This function can be replaced by ereg_replace.

55. strtr string replacement
Syntax: string strtr (string str, string from, string );
Replace the string 'str' with the from character. If the from and to characters are different, the extra characters are ignored. This function is replaced by characters rather than words or strings.

56. Use substr to obtain some strings.
Syntax: string substr (string, int start, int [length]);

57. Replace the substr_replace string
Syntax: string substr_replace (string, string replacement, int start, int [length]);
Extract the string from the string and replace it with the string replacement. The start and length parameters are defined and used in the same way as subxstr.

58. trim truncates spaces at the beginning and end of a string.
Syntax: string trim (string str );

59. Change the first character of the string to uppercase in ucfirst.
Syntax: string ucfirst (string str );

60. ucwords converts the first letter of each word in the string to uppercase.
Syntax: string ucwords (string str );

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.