The following small series will provide you with a detailed explanation of the built-in PHP string processing functions. I think this is quite good. now I will share it with you and give you a reference. Let's take a look at the features of the string.
1. other types of data are used in string-type processing functions. after the data is automatically converted to a string
"; // Cdef // The string echo substr (123456,2, 4) will be automatically converted using numbers; // 3456?>
2. strings can be viewed as arrays and as character sets.
"; // However, to distinguish arrays, the following echo $ str {2 }."
";?>
Powerful built-in string processing functions
1. common string output functions
Echo ()
Print ()
Die () ---- exit ()
Printf () format the string
Sprintf () returns the formatted string
2. common string formatting functions
Remove characters
Ltrim (); remove the string on the left (spaces are removed by default)
Rtrim (); remove the string on the right
Trim (); remove the strings on both sides
"; Echo strlen (ltrim ($ str ))."
"; Echo strlen (rtrim ($ str ))."
"; Echo strlen (trim ($ str ))."
"; $ Str1 =" 123 This is Test "; // The second parameter specifies the character (string) echo ltrim ($ str1, '1') to be deleted ')."
"; // Delete all numbers 0 .. 9 indicates the echo ltrim range ($ str1, '0 .. 9 ')."
";?>
Add string
Str_pad (); add a string (added on the right by default)
"; // Add echo str_pad ($ str, 10," @ ", STR_PAD_BOTH) on both sides )."
"; // Add echo str_pad ($ str, 10," @ ", STR_PAD_LEFT) from the left )."
";?>
Case-sensitive conversion
Strtolower (); all characters are converted to lowercase letters.
Strtoupper (); all characters are converted to uppercase letters
Ucfirst (); converts the initial letter to uppercase.
Ucword (); the first letter of each word is converted to uppercase
";echo strtolower($str)."
";echo ucfirst($str)."
";echo ucwords($str)."
";?>
String formatting related to HTML tags
Nl2br (); the function inserts an HTML line break (
).
Htmlentities (); the function converts characters to HTML objects.
Htmllspeciachars (); function converts some predefined characters into HTML objects.
The predefined characters are:
& (And number) become &
"" (Double quotation marks)"
''(Single quotes)'
<(Less than) becomes <
> (Greater than) become>
Stripslashes (); the function deletes the backslash added by the addslashes () function.
The addslashes () function adds a backslash before the specified predefined character.
The predefined characters are:
Single quotes (')
Double quotation marks (")
Backslash (\)
NULL
Strip_tags (); function removes HTML, XML, and PHP labels.
"; // Function converts characters to HTML objects. Echo htmlentities ($ _ GET ["str"], ENT_NOQUOTES )."
"; // Function converts some predefined characters into HTML objects. Echo htmlspecialchars ($ _ GET ["str"])."
"; // Remove \ echo stripslashes ($ _ GET [" str "]) added by the addslashes () function."
"; // Use echo htmlentities (stripslashes ($ _ GET [" str "]) in combination."
"; // Function removes HTML, XML, and PHP labels. Echo strip_tags ($ _ GET ["str"])."
";?>
Number_format (); the function uses a thousand-bit grouping to format numbers.
"; Echo number_format ($ )."
"; // Three decimal places are retained. the decimal places are separated by commas (,). The decimal places are separated by". "echo number_format ($ a, 3 ,'.',',')."
";?>
Strrev (); function reverse string
";echo strrev($str)."
";?>
Md5 ();
MD5 hash of the function compute string.
The md5 () function uses RSA Data Security, including the MD5 packet excerpt algorithm.
If the calculation succeeds, the calculated MD5 hash is returned. if the calculation fails, false is returned.
Md5_file ();
MD5 hash of the function compute file.
The md5 () function uses RSA Data Security, including the MD5 packet excerpt algorithm.
If the calculation succeeds, the calculated MD5 hash is returned. if the calculation fails, false is returned.
3. string comparison functions
Strcmp (); the function compares two strings.
0-if the two strings are equal
<0-if string1 is smaller than string2
> 0-if string1 is greater than string2
Strcasecmp ();
Strnatcmp ();
0){ echo '$str1>$str2';}else{ echo '$str1<$str2';}?>
The above detailed explanation of the built-in PHP string processing function is all the content that I have shared with you. I hope to give you a reference and support for PHP.