Looking for somewhere to host your site? Browse our PHP web hosts section!

Home > Code Snippets > Remove whitespace from a text string using the PHP trim function

Remove whitespace from a text string using the PHP trim function

Description

If you use a form on your site then you'll know that user input can often have white space before or after the text as the person filling in the form field sometimes accidentally adds spaces. This handy function will remove the whitespace from the beginning or end of the string.

The code

There was a problem whilst attempting to load the source code.

Get the code

Download the file to your computer: Click here to get the file