The explode () function can be used to split character functions in PHP, but there must be a rule for using this function, such as separating the | or by other characters, so that we can use the explode to divide the string into an array 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 |
|
|
<?php
$test = ' 472347127,893372115,850965403 ';
$r =explode (",", $test);
for ($i =0; $i <sizeof ($r); $i + +)
{echo $i. "." $r [$i]. "";}
?> |
Output: 0.472347127 1.893372115 2.850965403
Example Two
| The code is as follows |
|
|
<?php
$a = "893372115,472347127,850965403";
$b =explode (",", $a);
foreach ($b as $BB)
{echo $bb. "";//print_r ($b);}
?> |
Output: 893372115 472347127 850965403 PHP
Comma split string
Dividing a string into an array using the EXPLODE function
| The code is as follows |
|
|
<?php
$source = "HELLO1,HELLO2,HELLO3,HELLO4,HELLO5";//separating strings by commas
$hello = Explode (', ', $source);
for ($index =0; $index <count ($hello); $index + +) {
echo $hello [$index];echo "</br>";
}
?> |
Split function for character segmentation
| code is as follows |
&nbs P; |
|
<?php
//separator can be a slash, dot, or horizontal line
$date = "04/30/1973"; & nbsp
List ($month, $day, $year) = Split (' [/.-] ', $date);
Echo Month: $month; Day: $day; Year: $year <br/>n ";
|