php function for remove spaces from a string

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





// The original text string with whitespace at the end

$textString = "This is some text with a space after it ";



// Remove the whitespace

$trimmedTextString = trim($textString);



// Display the new text string

echo $trimmedTextString;



?>

Posted in |