Ad space (banner)
๐Ÿ˜PHP Lessons
Lesson 20 / 68

Splitting and Joining Strings (explode, implode)

In this lesson you will learn to split and join strings in PHP with explode and implode, so you can reshape text data such as CSV at will. This is for anyone searching for "PHP explode implode how to use".

explode(delimiter, string) breaks a string into an array. Going the other way, implode(delimiter, array) collects an array into a single string. Combining the two lets you swap delimiters, strip out unwanted spaces, and generally reshape text at will.

The sample code splits the comma-separated $csv into the array $fruits with explode(",", $csv), then rebuilds it with a different delimiter using implode(" / ", $fruits).

A common stumbling block for beginners is the argument order. Both take "delimiter first, data second", but people who have used split and join in other languages often remember it backwards.

This pairing appears constantly in real business systems, from reading CSV files to parsing logs. Parsing a list of tags submitted through a form is another everyday use.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run PHP directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)