How to convert string to array using comma in php

藏色散人
Release: 2023-03-05 06:34:02
Original
3123 people have browsed it

php method to use commas to convert a string into an array: first create a PHP sample file; then use the "explode(",",$str)" method to break up a string into an array .

How to convert string to array using comma in php

Recommended: "PHP Video Tutorial"

Strings are broken into arrays

<?php
$str = "Hello world. I love php!";
print_r (explode(" ",$str));
?>
Copy after login

Use explode to break up a string into an array. However, explode uses a certain character to break it up. For example, in the above example, the first parameter in the parentheses of explode is a space, and the second parameter is a space. is the string we are going to scramble, so concatenation means breaking the $str string into characters through spaces.

Because the content of our string is Hello world. I love php!

Each word is separated by a space, then after we break it up by spaces, our string will be It can be turned into an array.

If our Hello, world, Ilove, php!

are separated by commas, then we modify

explode(“,”,$str) first Just fill in the commas "," for each parameter.

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

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!