How do I remove extra spaces at the end of a string using regex (preg_replace)?
$string = "some random text with extra spaces at the end ";
How do I remove extra spaces at the end of a string using regex (preg_replace)?
|
||||
|
There is no need of regex here and you can use
But if you want a regex based solution you can use:
The regex used is
Basically we replace trailing whitespace characters with nothing ( |
|||||||||||||||||
|
You can use rtrim |
|||
|
You don't really need regex here, you can use the rtrim() function.
See also : |
|||||||||||||
|
You can use trim() to do this: |
|||||||||||||
|
you can use php trim and preg_replace for this. to see complete example click this link http://akhleshit.blogspot.com/2013/04/remove-extra-spaces-from-string-in-php.html |
|||
|