Hey,Hello Folks,
If you need to see an example of laravel remove all spaces from string. you can see laravel remove all whitespace from string. step by step explain how to remove spaces from string in laravel. you can understand a concept of how to remove space from string in laravel.
Here, i will give you simply two ways to remove all spaces from string in laravel project. we will use str_replace()
you can use this example with laravel 6, laravel 7, laravel 8, laravel 9 and laravel 10 version.
Example 1: using str_replace()
<?php
namespace App\Http\Controllers;
class DemoController extends Controller
{
/**
* Write code on Method
*
* @return response()
*/
public function index()
{
$string = "Hi, This is from HDTuto.com";
$string = str_replace(' ', '', $string);
dd($string);
}
}
Output:
Hi,ThisisfromHDTuto.com
Example 2: using preg_replace()
<?php
namespace App\Http\Controllers;
class DemoController extends Controller
{
/**
* Write code on Method
*
* @return response()
*/
public function index()
{
$string = "Hi, This is from HDTuto.com";
$string = preg_replace('/\s+/', '', $string);
dd($string);
}
}
Output:
Hi,ThisisfromHDTuto.com
I hope it can help you...
Do you like below Tutorials ?
- Multidimensional Array Search By Value in PHP
- Laravel Install Font Awesome Icons Example
- How to Use Moment JS in Laravel?
- Angular 9 Get Environment Variables Example
- Angular Delete a Component From Cli Example
- How to Upload File from Local to Server using SSH?
- Angular Use CKEditor Example Tutorial
- How to Use Multiple Select Dropdown in Laravel?