Home > Backend Development > PHP Problem > How to convert array by space in php

How to convert array by space in php

藏色散人
Release: 2023-03-14 12:08:02
Original
2140 people have browsed it

php method to convert array by space: 1. Create a new php file; 2. Save the string to be split in the $str variable; 3. Use the explode() function to convert the string in the previous step to an array with spaces. The split and returned array is stored in the $res variable; 4. Use print_r() to print the array on the page.

How to convert array by space in php

#The operating environment of this article: Windows 7 system, PHP version 7.4, Dell G3 computer.

php How to convert a string into an array by spaces?

Create a new PHP file named test.php to explain how PHP splits a string into an array by spaces.

How to convert array by space in php

In the test.php file, use the header() method to set the encoding format of the page to utf-8 to avoid garbled characters when the page outputs Chinese.

How to convert array by space in php

In the test.php file, save the string to be split in the $str variable.

How to convert array by space in php

In the test.php file, use the explode() function to split the string in the previous step by spaces, and the returned array is stored in the $res variable.

How to convert array by space in php

In the test.php file, use print_r() to print the array on the page.

How to convert array by space in php

Open the test.php file in the browser to view the results.

How to convert array by space in php

Recommended study: "PHP Video Tutorial"

The above is the detailed content of How to convert array by space in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template