In this tutorial you will learn about the Laravel str replaceLast() function Example and its application with practical example.
In this article, I’ll show you how to use laravel Str::replaceLast function with example. We will show example of laravel Str::replaceLast function in laravel. In this tutorial, we will create example to demonstrate the use of Str::replaceLast function.
Laravel Str::replaceLast method
The Str::replaceLast method replaces the last occurrence of a given value in a string.
Example:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Controllers\FileController; use Illuminate\Support\Str; class HomeController extends Controller { /** * Show the application dashboard. * * @return \Illuminate\Contracts\Support\Renderable */ public function index() { $replaced1= Str::replaceLast('example', 'tutorial', 'I will show example'); dd($replaced1); // output - We will show tutorial $replaced2 = Str::replaceLast('the', 'a', 'the quick brown fox jumps over the lazy dog'); dd($replaced2); // the quick brown fox jumps over a lazy dog } } |
Output:-
1 2 |
"We will show tutorial" "the quick brown fox jumps over a lazy dog" |