Laravel preg_replace_array() Function Example

10-Apr-2023

.

Admin

Laravel preg_replace_array() Function Example

Hello Friends,

In this blog, I will learn you replace pattern in the string sequentially using an array in laravel application. The preg_replace_array function replaces a given pattern in the string sequentially using an array.

Here I will give full example for preg_replace_array function in laravel. So let's see the bellow example.

Example :


/**

* The attributes that are mass assignable.

*

* @var array

*/

public function index()

{

$string = 'The event will take place between :start and :end';

$replaced = preg_replace_array('/:[a-z_]+/', ['8:30', '9:00'], $string);

dd($replaced);

// Output

// The event will take place between 8:30 and 9:00

}

Output :

The event will take place between 8:30 and 9:00

It will help you...

#Laravel 7

#Laravel

#Laravel 6