In PHP, the explode () function is used to cut the string into an array. The explode Array

Source: Internet
Author: User

In PHP, the explode () function is used to cut the string into an array. The explode Array

The function of explode () is used to split another string into arrays.

For example:

String

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

After separation by space:$ Pieces = explode (", $ pizza );

$ Pieces is the split array. Let's print it and see it.

<? Php $ pizza = "1st 2nd 3rd 4th 5th"; $ pieces = explode ("", $ pizza); foreach ($ pieces as $ val) {echo $ val. "<br>";} piece1piece2piece3piece4piece5piece6

Example 2: Separate data by commas

<? Php $ string = 'Today the sun is very big, and we have not gone out. At noon, we had a good time dining room! '; $ String_arr = explode (",", $ string); foreach ($ string_arr as $ val) {echo $ val. "<br> ";}

Output result:

Today, the sun is very large.
We did not go out. We will have dinner in the dining room at noon.
Happy!

The above is an example of using the explode () function to cut strings into arrays in PHP. I hope to help you. If you have any questions, please leave a message, the editor will reply to you in time!

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.