Home>

The role of the explode () function:use one string to split another,Break into arrays.The following uses this article to introduce you to the use of explode () function to cut strings into arrays in PHP.

The role of the explode () function:use one string to split another,Break into arrays.

E.g:

String

$pizza="1st 2nd 3rd 4th 5th 6th";

After dividing by spaces:$pieces=explode ("", $pizza);

$pieces is the split array,Let's print it out

<?php
$pizza="1st 2nd 3rd 4th 5th 6th";
$pieces=explode ("", $pizza);
foreach ($pieces as $val) {
  echo $val. "<br>";
}
piece1
piece2
piece3
piece4
piece5
piece6

Example 2:Split by comma

<?php
$string="The sun is very big today,None of us went out.
At noon we eat in the cafeteria,Very happy! ";
$string_arr=explode (",", $string);
foreach ($string_arr as $val) {
  echo $val. "<br>";
}

Output results:

The sun is very big today

None of us went out.Let's eat in the cafeteria at noon

Very happy!

php
  • Previous Simple implementation of jQuery barrage effect
  • Next Android Custom Rounded ImageView Control