Wednesday 18 December 2013

How to split a String as array in PHP

explode:

        explode - Split a string by a substring or a string.

* It returns  an array of strings, each of which is a substring formed by    splitting  the given string.

Example:

<?php

  $str = "hello welcome to explode concept";
  $string = explode(" ",$str);

  echo $string[0];      // returns hello
  echo $string[1];      //returns welcome
  echo $string[2];      //returns to
  echo $string[3];      //returns explode
  echo $string[4];      //returns concept

?>

Note: 

Here i splitted where a empty space is available. same we can split based on a char or number.

I hope it  will helps you.


  

No comments:

Post a Comment