We have given a string and the task is to remove white space only from beginning of a string or end from a string str in PHP. In order to do this task, we have the following methods in PHP:
Method 1: Using ltrim() Method: The ltrim() method is used to strip whitespace only from the beginning of a string.
Geeks for Geeks Length of String: 20
Method 2: Using rtrim() Method: The rtrim() method is used to strip whitespace only from the end of a string.
Geeks for Geeks Length of String : 19
- How to remove all white spaces from a string in PHP ?
- CSS | white-space Property
- How to insert spaces/tabs in text using HTML/CSS?
- How to remove only rotation controls of a canvas-type text using Fabric.js ?
- How to tab space instead of multiple non-breaking spaces (nbsp)?
- How to validate if input in input field has full width string only using express-validator ?
- How to remove the first character of string in PHP?
- Remove new lines from string in PHP
- How to remove extension from string in PHP?
- How to remove line breaks from the string in PHP?
- How to remove portion of a string after a certain character in PHP?
- How to remove all non-printable characters in a string in PHP?
- How to remove all leading zeros in a string in PHP ?
- How to remove control characters from PHP string ?
- How to Remove Special Character from String in PHP ?
- Remove a cookie using PHP
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.