Mega Code Archive

 
Categories / Php / Code Snippets
 

This shows how to use the trim function to remove white spaces

from either side of a string <?php //trimming white space from a string //our two strings $string1 = " spaces before"; $string2 = " spaces before and after "; //remove the whitespace $trimmed_string1 = trim($string1); $trimmed_string2 = trim($string2); //display the text echo $trimmed_string1; echo "<br>"; echo $trimmed_string2; ?>