How to Split a String in PHP using explode()?

Susan Sarandon
Release: 2024-11-14 15:10:01
Original
201 people have browsed it

How to Split a String in PHP using explode()?

PHP: Split String

In PHP, splitting a string by a delimiter can be achieved using the explode() function. This function takes two arguments: the delimiter and the string to be split. The resulting array will contain the parts of the original string that were separated by the delimiter.

For instance, if you have the string "a.b" and you want to split it by the period (.) delimiter, you would do the following:

$parts = explode('.', $string);
Copy after login

The $parts array will now contain two elements: "a" and "b".

You can also directly assign the parts of the resulting array to variables, like this:

list($part1, $part2) = explode('.', $string);
Copy after login

In this case, $part1 will be assigned the value "a" and $part2 will be assigned the value "b".

The above is the detailed content of How to Split a String in PHP using explode()?. For more information, please follow other related articles on the PHP Chinese website!

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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template