- $ Str = "Hello world. It's a beautiful day .";
- Print_r (explode ("", $ str ));
- ?>
2. example of string connection:
- // Define a string
- $ Str1 = "Hello World! ";
-
- $ Str2 = "PHP! ";
- // Separate the two strings with spaces
- $ Str3 = $ str1. "". $ str2;
-
- // Output the connected string
- Echo $ str3;
3. string truncation substr (), mb_substr example:
- $ Str = "login.com ";
- Echo substr ($ str, 2); // gin.com
- Echo substr ($ str, 2, 3); // gin
- Echo substr ($ str,-2); // Obtain the negative value of om from the end.
- ?>
-
However, when you intercept Chinese strings, garbled characters are easily displayed, because one Chinese character is two bytes while one English letter is one byte. Solution: 2, mb_substr (). use the same method as substr, but enable extension = php_mbstring.dll extension in php. ini. Example:
- Echo mb_substr ("int Hello", "UTF-8"); // nt you
- ?>
3. string search strpos () definition and usage the strpos () function returns the position where the string first appears in another string. If this string is not found, false is returned. Syntax strpos (string, find, start) The parameter description string must specify the string to be searched. find must specify the characters to be searched. Start is optional. Specifies the location where the search starts Example:
- $ String = '#11 #22 #33 #44 #55 #66 #77 ';
- $ Find = '#55 ';
- If (strpos ($ string, $ find) === false ){
- Echo 'not found ';
- } Else {// bbs.it-home.org
- Echo 'found ';
- }
- Echo strpos ($ string, $ find );
- ?>
4. string replacement str_replace example:
- $ Replace_string = 'You are very bad, really bad ';
- $ Replace_string_ B = 'bad ';
- $ Replace_string _ = str_replace ($ replace_string_ B, '*', $ replace_string, $ I );
- Echo $ replace_string _;
- ?>
Replace substr_replace with the specified position
- Echo substr_replace ("Hello world", "php12", 6); // Hello php12
- ?>
-
5. the string-to-case function converts a string to lower-case strtolower (): This function converts all characters of the input string parameter to lower-case, and places the string back in a small form. example:
- $ Str = "I love YOU ";
- $ Str = strtolower ($ str );
- Echo $ str;
- ?>
-
Output result: I love YOU Convert character to uppercase strtoupper (): This function is opposite to the strtolower function. it converts all characters of the input character parameter to uppercase and returns the string in uppercase. the usage is the same as that of strtolowe. Convert the first character of the string to usfilst (): This function is used to change the first character of the string to uppercase. This function returns the first character of the string. The usage is the same as that of strtolowe. Convert the first character of each word in a string to uppercase ucwords (): This function converts the first character of each word in the input string to uppercase. For example, "hello world". after this function is processed, "Hello Word" is returned ". The usage is the same as that of strtolowe. >>> View more php tutorials < |