Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

explode
php
strings

What is explode() in PHP?

Educative Answers Team

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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));
?>

RELATED TAGS

explode
php
strings
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring