PHP Remove Whitespace from Beginning and End of String Example

By Hardik Savani November 5, 2023 Category : PHP

Hi Dev,

Now, let's see an example of php remove whitespace from beginning and end of string. I would like to share with you php remove space from beginning and end of string. let’s discuss about how to remove space from start and end of string in php. We will look at an example of remove first and last space from string in php.

We will use trim() php function to remove space from start to end of string in php. you can also use this example with laravel. so, let's see the simple example code with output.

index.php

<?php

$myString = " Hello ItSolutionStuff.com ";

$newString = trim($myString);

var_dump($newString);

?>

Output:

string(25) "Hello ItSolutionStuff.com"

I hope it can help you...

Tags :
Shares