How to split String in PHP


Answers

  • April 22, 2020

    explode() is a built in function PHP, which will breaks the String with given delimeter(separator)

    array explode(separator, OriginalString, NoOfElements)

     

    Example 1: explode(" ","Split String in PHP");

    If we not pass NoOfElements, then it will split entire text and returns array

    Output

    array(4) { 
        [0]=> string(5) "Split" 
        [1]=> string(6) "String" 
        [2]=> string(2) "in" 
        [3]=> string(3) "PHP"
     }

     

    Example 2: explode(" ","Split String in PHP",2);

    Here we passed NoOfElements is 2, so explode split string into 2 parts.

    Output

    array(2) { 
         [0]=> string(5) "Split" 
         [1]=> string(13) "String in PHP" 
     }

     

    Comment

Have More Question?

Subscribe For Daily Updates

Flutter Questions
Android Questions