- $date = "08-30-2010";
- The delimiter can be a slash, a dot, or a horizontal line
- List ($month, $day, $year) = Split (' [/.-] ', $date);
- Output to a different time format
- echo "Today is: $year year $month month $day Day";
- ?>
Copy Code
Note that pattern is a regular expression, and if you want to use a split character that is a special character in a regular expression, first escape it.
You are 2 and divide the first four fields in the/etc/passwd:
Copy Code
If there are n items in a string that match pattern, the returned array will contain n+1 cells. For example, if pattern is not found, an array with only one cell is returned. Of course, this is true if the string is empty.
Example 3, parse the date that may be split with a slash, dot, or horizontal line:
- The delimiter can be a slash, a dot, or a horizontal line
- $date = "04/30/1973";
- List ($month, $day, $year) = Split (' [/.-] ', $date);
- echo "Month: $month; Day: $day; Year: $year
\ n ";
- ?>
Copy Code
Note: pattern is a regular expression. If you want to use a split character that is a special character in a regular expression, first escape it. If you feel that the PHP function split () (or any other Regex function) behaves strangely, read the regex.7 file contained in the regex/subdirectory of the PHP release package. This file is a manual page format and can be read with commands like man/usr/local/src/regex/regex.7.
For a piece of text according to the word segmentation, because the text may be mixed in English and Chinese, and PHP function strlen can only calculate the number of bytes of the string, so that their own implementation of several functions, share under.
Example 1, calculates the total length of a character.
0xa0) {$ccLen + +; $ind + +;} else{$ccLen + +;}} return $ccLen;}? >
Example 2, which intercepts a string from the left.
Example 3, the given text, by the number of cuts in the array (suitable for short text, long articles can be processed directly without a separate part)
0) {$str _tmp=ccstrleft ($str _tmp, $smslen); Array_push ($arr _cont, $str _tmp); $i +=strlen ($str _tmp); $str _tmp=substr ($ Content, $i, strlen ($content));} return $arr _cont;} by bbs.it-home.org?>
Test:
'; $smslen =3;//intercept length Print_r (splitcontent ($str, $smslen));? >
Split Result: Array ([0] + a calculation [1] = [2] = [+] = mixed 1[3] = 234[4] = string [5] = length [6] = abc[7] + D)
|