Basic PHP Programming Question:
How To Remove Leading and Trailing Spaces from User Input Values in PHP?

Answer:
If you are taking input values from users with a Web form, users may enter extra spaces at the beginning and/or the end of the input values. You should always use the trim() function to remove those extra spaces as shown in this PHP script:
<?php
$name = $_REQUEST("name");
$name = trim($name);
# $name is ready to be used...
?>
<?php
$name = $_REQUEST("name");
$name = trim($name);
# $name is ready to be used...
?>
Previous Question | Next Question |
How To Remove the New Line Character from the End of a Text Line in PHP? | How to Find a Substring from a Given String in PHP? |