PHP split string and output array character example
The explode () function can be used in the split character function in PHP, but there must be a rule for using this function, such as separating by | or separating with other characters, so that we can use explode to divide the string into arrays and then use the for traversal output, here are a few examples.
The explode () function splits the string into arrays.
Grammar
Explode (Separator,string,limit)
Example One
The code is as follows |
|
$test = ' 472347127,893372115,850965403 '; $r =explode (",", $test); for ($i =0; $i<> {echo $i. ". $r [$i]." ";} ?> |
Output: 0.472347127 1.893372115 2.850965403
Example Two
The code is as follows |
|
$a = "893372115,472347127,850965403"; $b =explode (",", $a); foreach ($b as $BB) {echo $bb. "";//print_r ($b);} ?> |
Output: 893372115 472347127 850965403 PHP
Comma-delimited string
Using the explode function to split a string into an array
code 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 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 "; ?> |
http://www.bkjia.com/PHPjc/873237.html www.bkjia.com true http://www.bkjia.com/PHPjc/873237.html techarticle PHP split string and output array character example the split character function in PHP can use the explode () function, but there must be a rule to use this function, such as by | separating or using other words ...