PHP String Handling functions

Source: Internet
Author: User

1: String conversion
(1): Binary conversionA): Bin2Hex (string $str) binary to hex B): Hex2bin (String $str) hex-to-binary (2): Special character processing functionA): Addslashes (String $str) escapes special characters such as ' turn to \ '; b): Addcslashes (string $str) use the backslash in the C language style to escape the word such as ' to \ ' in the string; c): Stripslashes (String $str) restores the escape character D): Stripcslashes (String $str) restores the escape character e): Htmlspeciachars (string $str) special character processing F): Htmlspeciachars_decode (String $str) restores the path-handling special characters (3) uppercase lettersA): String Ucwords (String $str) converts the first letter of each word in a string to uppercase B): String Ucfirst (String $str) converts the first letter of the string to uppercase C): String Lcfirst (String $STR) Converts the first letter of the string to lowercase D): string Strtoupper (String $str) Converts the letter of the string to uppercase string Strtolower (string $str) Converts the letter of the string to lowercase (4) Character and ASCLL code conversionA): Char chr (char $str) convert ASCLL code to character B): int ord (int number) converts the character to ASCLL code (5) string EncryptionA:) string MD5 (string $str)
2: String Lookup
(1): int Strpos (String $str, String $needle, $offert) is case-sensitive, the return type is number-"find the character where the string is located $str the characters that are being looked up, $needle find the character, $offert set Starting position------homogeneous function------------stripos ()-Find the first occurrence of a string (case-insensitive) strrpos ()-Calculates the position of the last occurrence of the specified string in the target string Strripos ()- Calculates the last occurrence of the specified string in the target string (case-insensitive) (2): String Strstr (String $haystack, mixed $needle [, bool $before _needle = false]) Case-sensitive Before_needle if TRUE,STRSTR () returns the portion of the needle before the position in haystack. ------Homogeneous function------------stristr () is case insensitive (3): String STRRCHR (String $haystack, mixed $needle)-finds the last occurrence of a specified character in a string   Returns a portion of the haystack string, starting at the last occurrence of needle, until the end of haystack. (4): int Preg_match (String $pattern, String $subject [, Array & $matches [, int $flags = 0 [, int $offset = 0]]) Row a regular expression match (5): String substr ((string $string, int $start [, int $length]) substring of strings
3: String formatting and substitution
(1): String trim (string $haystack) removes whitespace from both ends------the same function------------LTrim () strips the Left blank RTrim () and removes the right blank chop (), etc.  Same as RTrim () (2): String Str_replace (mixed $search, mixed $replace, mixed $subject [, int & $count]);  If there are no special substitution requirements (such as regular expressions), you should use this function to replace ereg_replace () and Preg_replace (). -----------Similar functions-------------mixed substr_replace (mixed $string, mixed $replacement, mixed $start [, mixed $length] ) Mixed str_ireplace (mixed $search, mixed $replace, mixed $subject [, int & $count])
4: Output function 
echo
print () Pirnt_r () Var_dump () Four differences echo is similar to print usage, but echo can print multiple "," separate, pirnt_r mainly used to print objects and arrays, Var_dump () hit Information about the variables-----------similar functions------------printf () formatted output sprintf ()-Return a formatted string vprintf ()-Output formatted string sscanf ()-parses the input characters according to the specified format fscanf ()-Formats the input from the file
5: Formatting functions String Number_format (float $number, int $decimals = 0, string $dec _point = '. ', string $thousands _sep = ', ') string Money_format (string $format, float $number)6: Other functions
the int strlen () character length Boolean StrComp () character compares the character array explode (string $str, String $needle) to the string implode (array $ar R,string $needle) converts an array into characters equal to join

PHP String Handling functions

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.