Php splits the string and outputs an array character example. Php splits the string and outputs an array character example. in php, you can use the explode () function to split the character. However, this function must have a regular pattern, for example, the string is separated by | or separated by other words, and the array character is output.
The explode () function can be used to split character functions in php, but this function must have a regular pattern, for example, separating with | or other characters, in this way, we can directly use explode to divide the string into arrays and then use for traversal output. Here are several examples.
The explode () function separates strings into arrays.
Syntax
Explode (separator, string, limit)
Example 1
| The code is as follows: |
|
| $ Test = '2014 372115,850965403 '; $ R = explode (",", $ test ); For ($ I = 0; $ I {Echo $ I. ".". $ r [$ I]. "";} ?> |
Output: 0.472347127 1.893372115 2.850965403
Example 2
| The code is as follows: |
|
| $ A = "893372115,472369127, 850965403 "; $ B = explode (",", $ ); Foreach ($ B as $ bb) {Echo $ bb. ""; // print_r ($ B );} ?> |
Output: 893372115 472347127 850965403 PHP
Comma-separated string
Use the explode function to split a string into an array
| The code is as follows: |
|
| $ Source = "hello1, hello2, hello3, hello4, hello5"; // separate strings by commas $ Hello = explode (',', $ source ); For ($ index = 0; $ index Echo $ hello [$ index]; echo" "; } ?> |
Split function for Character Segmentation
| The code is as follows: |
|
| // The delimiter can be a diagonal line, a dot, or a horizontal line. $ Date = "04/30/1973 "; List ($ month, $ day, $ year) = split ('[/.-]', $ date ); Echo "Month: $ month; Day: $ day; Year: $ year N "; ?> |
The delimiter function can use the explode () function to separate characters in php, but this function must have a regular pattern, for example, separating with | or using other words...