PHP: how to use space to split text into arrays-php Tutorial

Source: Internet
Author: User
PHP uses space to split text into arrays. php reads text files line by line, processes space-separated text, and outputs the method as an array. Text file text.txt content: 1 Field 1 field 22 field 1 field 23 Field 1 field 24 field 1 Field 1 field 2 text and text are separated by spaces, processed with php, output as an array, below is the code & lt ;? Php $ filefopen (t PHP uses spaces to split text into arrays

Php reads text files line by line, processes text separated by spaces, and outputs the method as an array.

Text file text.txt content:

1 Field 1 field 2 Field 1 field 2 3 Field 1 field 2 4 Field 1 field 2

Text and text are separated by spaces. php is used for processing and the output is an array. here is the code.

  

? Output result:

Array ([0] => 1 [1] => Field 1 [2] => Field 2) array ([0] => 2 [1] => Field 1 [2] => Field 2) array ([0] => 3 [1] => Field 1 [2] => Field 2) array ([0] => 4 [1] => Field 1 [2] => Field 2)

In this way, PHP uses spaces to split text into arrays.

This php Tutorial is produced by the JS code station.

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.