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

How to convert array by space in php

藏色散人
藏色散人Original
2021-12-10 10:29:112101browse

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!

Statement:
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