Describes how to split strings in PHP. Result: Array ([0] 1 [1] 2 [2] 3 [3] 4) defines and uses the str_split () function to split the string into arrays. The length syntax indicates the number of each string.Result: Array ([0] => 1 [1] => 2 [2] => 3 [3] => 4)
Definition and usage
The str_split () function separates strings into arrays.
Length indicates the number of strings.
Str_split (string, length) the default length is 1. if it is str_split ($ str, 2), the result is Array ([0] => 12 [1] => 34)
If it is $ str = '1 2 3 4 ', use the explode () function explode ('', $ str) to separate it by space.
If the content of an article is intercepted by the number of characters: Use the strlen () function and substr () string truncation function to split the string in PHP. for example:
- <? Php $ len = strlen ($ row ['Game _ detail']);
- // Obtain the length of the string;
- If ($ len> 102)
- // Judge whether a string is greater than 102 and outputs 102 strings.
- {Echo $ s = substr ($ row ['Game _ detail'],
0,102); echo '...';
- }
- Else {echo $ row ["game_detail"];
- // Otherwise, all are output;
- }
- ?>
That is, make a judgment before the output .. Strlen (String name ).. The range of substr (string, 0,102) to be split is 0-103. These are all the methods for separating strings in PHP.
Merge result: Array ([0] = 1 [1] = 2 [2] = 3 [3] = 4) defines and uses the str_split () function to split the string into an Array. The length syntax indicates the number of each string...