Your Open Source

 
Related Links
PHP  >>  String

String

Explode Function in PHP

The explode() function is used to break a string into an array.

Syntax is: explode(separator,string,limit)

The first parameter is the separator, this is required, it specifies where to break the string. The second parameter is the given string, of course, this is required. The third is the limit, this is optional, it specifies the maximum number of array elements to return.

Example:

<?php

$str = "PHP is fun!.";
print_r (explode(" ",$str));
?>

Output is:

Array
(
[0] => PHP
[1] => is
[2] => fun!.
)

Another example, this time with the third parameter:

<?php

$str = "PHP is fun!."

print_r(explode(" ", $str, 2));
?>

Output is:

Array
(
[0] => PHP
[1] => is
)

  • hits 49
  • datetime Aug 01 09 01:32:56
  • author Lazywriter
  • rating

Rating : 12345

Comments

No Reply..

Quick Reply or Comments

Preview
Your Name:
Your Reply :
<> is a code tag
Enter the verification code: