What is explode() in PHP?

In PHP, the explode() function is used to split a string into a series of tokens (substrings extracted from the original string) based on a particular delimiter. In other words, the explode() function converts a string into an array.

svg viewer

Syntax

explode(separator, string, limit)
  • separator: Specifies the token where the string needs to split.

  • string: The string that needs to split.

  • limit: An optional parameter that specifies the number of array elements that should be returned.

Code 1

The following code runs the explode() function without the limit parameter.

<?php
$str = "Hello world. This is educative";
print_r (explode(" ", $str));
?>

Code 2

The following code runs the explode() function with the limit parameter.

<?php
$str = "Hello,world,This,is,educative";
print_r(explode(',',$str,2));
?>

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved