Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove white space from only beginning of a php string

i have a string like below

$string = ' florida'

how can i remove white space from beginning ONLY to form it like below.

$result_string = 'florida'

i am sorry if it is too easy question.

like image 299
user1458253 Avatar asked Jun 19 '12 08:06

user1458253


People also ask

How do you remove the white space at the beginning of a string?

String result = str. trim(); The trim() method will remove both leading and trailing whitespace from a string and return the result.

How do you remove spaces at beginning and at the at the in string PHP?

The trim() function removes whitespace and other predefined characters from both sides of a string. Related functions: ltrim() - Removes whitespace or other predefined characters from the left side of a string. rtrim() - Removes whitespace or other predefined characters from the right side of a string.

Which function is used to remove whitespace from beginning of the string?

Method 1: Using ltrim() Method: The ltrim() method is used to strip whitespace only from the beginning of a string.

Which function is used to remove whitespace from the start of the string PHP?

The trim() function in PHP removes whitespace or any other predefined character from both the left and right sides of a string. ltrim() and rtrim() are used to remove these whitespaces or other characters from the left and right sides of the string.


1 Answers

$string = ' florida'

$result_string = ltrim($string);

echo $result_string;// it will remove white spces from beganing
like image 122
Khurram Avatar answered Oct 13 '22 00:10

Khurram