ItSolutionStuff.com

PHP Remove Whitespace from Beginning and End of String Example

By Hardik Savani β€’ May 14, 2024
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: PHP
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

πŸ“Ί Subscribe on YouTube

We Are Recommending You

β˜…

How to Get Previous Month from Date in PHP?

Read Now β†’
β˜…

How to Get HTML Tag Value in PHP?

Read Now β†’
β˜…

MySQL Query to Get Current Year Data Example

Read Now β†’
β˜…

How to Remove White Space from String in PHP?

Read Now β†’
β˜…

How to Quick Run PHP Project on Localhost?

Read Now β†’
β˜…

How to Check If String is URL or Not in PHP?

Read Now β†’
β˜…

How to Convert Array Key to Lowercase in PHP?

Read Now β†’
β˜…

How to Upload Image using jQuery Ajax in PHP?

Read Now β†’
β˜…

How to Remove Empty Values from Array in PHP?

Read Now β†’
β˜…

How to Get Minimum Key Value of Array in PHP?

Read Now β†’
β˜…

How to access PHP variables in JQuery?

Read Now β†’
β˜…

How to Count Number of Files in a Directory in PHP?

Read Now β†’
β˜…

How to Find Day Name from Specific Date in PHP?

Read Now β†’
β˜…

How to Remove Null Values from Array in PHP?

Read Now β†’