Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • PHP Explode() Vs Split() Function

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 337
    Comment on it

    Hello Readers,

    In this blog, I am going to tell a small difference between Explode & Split function in PHP. Both the function do the same thing i.e split a string into array.

     

    But there is a minor difference that explode takes delimiter to split while split takes regular expression. This means the running time of explode is faster than split function.

     

    According to PHP Documentation : preg_split() is faster than split(), so really there isn’t much of a reason to use split() at all.

    Example of Explode() Function

    <?php
    
    
    $str = "welcome to Find Nerd";
    
    print_r (explode(" ",$str));  // split a string by string into array
    
    
    ?>
    
    Output: Array ( [0] => welcome [1] => to [2] =>Find [3] => Nerd)

     

    Example of Split() Function

    <?php
    
    
       $str = "w.t.f.n"
    
       print_r(split ("\.", $str)); // split a string into array  using regular expression.
    
    
    ?>


    Output: Array ( [0] => w [1] => t [2] => f [3] => n )

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: