R4R Team working to provide free of cost for experienced and freshers

Tutorials | Examples|Interview Questions and Answers|Java Tutorials| C Tutorials | C++ Tutorials | Spring Tutorials| Hibernate Tutorials | JSP Tutorials | Servelets Tutorials| C# Tutorials | PHP Tutorials etc , Basics | Download Software | Data Types | Variables | Constant | Storage & Classes | Operators | Decisions Making | Loops | Functions| Numbers | Arrays | Pointers | String | Datastructure | Expressions | Preprocessor Statement | I/O | Exception Handling | OOPs Tutorial | Classes and object |C++ Inheritance Overloading | Polymorphism | Abstraction | Encapsulation | Interfaces | Multithreading etc

PHP Programing language

explode() Functions in PHP
Previous Home Next

explode()

The explode() function breaks a string into an array.

Syntax:
explode(separator,string,limit)

In above syntax, "separator" specifies where to break the string, "string" string to split and "limit" specifies the number of array elements to return. Possible values limits are:

  1. > 0 : Returns an array with a maximum of limit element(s)
  2. < 0 : Returns an array except for the last-limit elements()
  3. 0 : Returns an array with one element

Example:

<?php
$str = 'Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday';

// zero limit
print_r(explode(',',$str,0));
print "<br>";

// positive limit
print_r(explode(',',$str,4));
print "<br>";

// negative limit 
print_r(explode(',',$str,-2));
?>    

Output:

Array ( [0] => Monday,Tuesday,Wednesday, Thursday,Friday,Saturday, Sunday ) 
Array ( [0] => Monday [1] => Tuesday [2] => Wednesday [3] => Thursday,Friday,Saturday, Sunday ) 
Array ( [0] => Monday [1] => Tuesday [2] => Wednesday [3] => Thursday [4] => Friday )

Previous Home Next