This article introduces some of the commonly used string functions in PHP, here to share to you, you can also give a friend in need a little reference, let's take a look at it
1. Get string length strlen ()
2. Remove blank string trim (), LTrim (), RTrim () to remove whitespace from the end of the string, the beginning of the string, and the ending of the string.
Trim (), LTrim (), RTrim () function delete the characters by default:
symbols |
ASCII code |
meaning |
“ ” |
0x20 |
Space |
"\ T" |
0x09 |
Tabs |
"\ n" |
0X0A |
Line break |
"\ r" |
0x0D |
Carriage return character |
"The" |
0x00 |
Null character |
"\X0B" |
0x0B |
Portrait tab |
Examgle$title = " programming php \ n"; $str 1 = LTrim ($title);//promgromming php \n$str2 = RTrim ($title);// Programming Php$str3 = Trim ($title);//programming PHP
You can use the trim () function with parameters to remove the opening or closing whitespace without deleting the tab $record = "fred\tflintstone\t35\twilma\t \ n"; $record = Trim ($record, "\r\n\ 0\x0b ");//The record value at this time is:" Fred\tflintstone\t35\twilma\t "
Change the case
Strtolower (), Strtoupper () operation of the entire string
Ucfirst () only the first character of a string, Ucwords () the first character of each word in the action string
EXAMPLE$STR1 = "FRED fintstone"; $str 2 = "Barney Rubble";p rint (Strtolower ($str 1));p rint (Strtoupper ($str 1));p rint ( Ucfirst ($str 2));p rint (Ucwords ($str 2));
Output Fred Fintstonefred Fintstonebarney Rubblebarney Rubble