$_POST["name"] = "Sam Yi ";
$_POST["title"] = " This title is strange";
$_POST["interest"] = "I have no interest";
If you echo the $_POST value,
<?php
echo $_POST["name"].",";
echo $_POST["title"].",";
echo $_POST["interest"].".";
?>
you will got this result :(useless space are highlighted in yellow)
Sam Yi , This title is strange,I have no interest.
To remove the useless space at begining or the end of the value, you can use a foreach to load all $_POST value to trim.
<?php
foreach ($_POST as $key => $val){
$_POST[$key] = trim($val);
}
echo $_POST["name"].",";
echo $_POST["title"].",";
echo $_POST["interest"].".";
?>
You will get this result:
Sam Yi,This title is strange,I have no interest.
Reference:
http://stackoverflow.com/questions/4710440/php-need-to-trim-all-the-post-variables
No comments :
Post a Comment