Steven
Steven

Reputation: 25314

How to trim leftmost and rightmost whitespaces of a string using PHP?

What function can I use?

Upvotes: 0

Views: 397

Answers (5)

Shoban
Shoban

Reputation: 23016

Checkout PHP Trim.

Upvotes: 0

Fifth-Edition
Fifth-Edition

Reputation: 365

http://php.net/manual/en/function.trim.php would be your best choice

Upvotes: 0

Gumbo
Gumbo

Reputation: 655765

Use trim to remove whitespace at the start and end of a string.

Upvotes: 3

pek
pek

Reputation: 18035

string trim ( string $str [, string $charlist ] )

This function returns a string with whitespace stripped from the beginning and end of str

Upvotes: 0

Sarfraz
Sarfraz

Reputation: 382881

left most

ltrim('text');

right most

rtrim('text');

but shortcut of above two is simply

trim('text');

Upvotes: 3

Related Questions