Php

Difference Between Split and Explode in PHP

The split() and explode() are two main string function in php. If you are working in php, You must have used these php function in your application. You have also faced some question in interviews regarding difference between php split and explode string function.

In this post, I will let you know what are the differences between Split() and Explode() php function with example.

Simple Usage and example of split() PHP function

The split() function is use to splits the string into an array using a regular expression.The split method returns an array of string data. PHP split() function takes three arguments, first parameter is pattern regular expression which is case sensitive, second is input string and third one is for limit: If the limit is set, the returned array will contain a maximum of limit elements with the last element containing the whole rest of string.

Warning
This function was DEPRECATED in PHP 5.3.0, and REMOVED in PHP 7.0.0.Alternatives of split function in php7 –

You can read more from Implode And Explode In PHP 7 tutorial.

Related Post

How to use PHP split Function

split(":", "this:is:a:string"); //returns an array that contains this, is, a, string.

Output :

Array(
[0] => this,
[1] => is,
[2] => a,
[3] => string
)

Simple Usage and Example of explode() PHP function

The php explode() function splits the string using delimiter and returns an array. PHP explode function takes three argument, first one takes delimiter as a argument, second one is target string and third one is limit : If limit is set and positive, the returned array will contain a maximum of limit elements with the last element containing the rest of string.

Simple Example and Demo of PHP explode function

The below example is used to explode the string using delimiter, The delimiter is this string. Passing first one argument as a delimiter and second one is source string.

explode ("this", "this is a string"); //returns an array that contains array "is a string"

Output

array([0] => "is a string")

Recent Posts

What is the Purpose of php_eol in PHP?

in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More

2 months ago

Laravel Table Relationship Methods With Example

This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More

2 months ago

Exploring the Power of Laravel Eloquent Join?

We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More

2 months ago

Quick and Easy Installation of Laravel Valet

in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More

3 months ago

What is Laravel Soft Delete and How Does it Work?

I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More

3 months ago

Common Practices for Laravel Blade Template

in this Laravel tutorial, I will explore common practices for using the Laravel Blade template with examples. Blade is a… Read More

3 months ago

Categories