Methods for using the explode () function to cut strings into arrays in PHP

Source: Internet
Author: User
Tags php explode
Explode () function: Splits the array by splitting another string with one string. The following article introduces you to the use of PHP explode () function cut string array, the need for friends can refer to the following

Explode () function: Splits the array by splitting another string with one string.

For example:

String

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

After dividing by space:$pieces = explode(” “, $pizza);

$pieces is the segmented array, we print it out to see

<?php$pizza = "1th 2nd 3rd 4th 5th 6th"; $pieces = Explode ("", $pizza); foreach ($pieces as $val) {  echo $val. " <br> ";} Piece1piece2piece3piece4piece5piece6

Example 2: Segmentation by commas

<?php$string = ' The sun is very big today, we have not gone out. At noon we eat in the canteen, are very happy! '; $string _arr = Explode (",", $string); foreach ($string _arr as $val) {  echo $val. " <br> ";}

Output Result:

The sun is very big today
None of us have gone out. We'll eat in the cafeteria at noon.
All very happy!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.