DeanWhitehouse Posted August 23, 2008 Share Posted August 23, 2008 I have this <?php $name = htmlentities($_POST['dbhost']); $name = trim($name); if(strlen($name) == 0) { echo alert("Enter your host address."); } ?> <form action="" method="post"> <input type="text" name="dbhost" value="<?php if(isset($_POST['dbhost']))echo $_POST['dbhost']; else{?>Database Host<?php } ?>" onClick="if(this.value == 'Database Host'){this.value='';}else {this.select();}" onBlur="if(this.value=='') this.value='Database Host';" title="Database Host"><br> <input type="submit" value="Continue" name="stage1" onClick="this.disabled=true"> <input type="reset" value="Reset"><br><input type="submit" value="Test" name="test"> </form> When i just enter a space , it doesnt show an error. ?? why is this Quote Link to comment https://forums.phpfreaks.com/topic/121033-solved-am-i-using-trim-correctly/ Share on other sites More sharing options...
AjBaz100 Posted August 23, 2008 Share Posted August 23, 2008 You should probably try wrapping the code in a If strlen() function.. I don't think trim can handle a null character. $name = htmlentities($_POST['dbhost']); if( $name ) { $name = trim($name); if(strlen($name) == 0) { echo alert("Enter your host address."); } } Quote Link to comment https://forums.phpfreaks.com/topic/121033-solved-am-i-using-trim-correctly/#findComment-623924 Share on other sites More sharing options...
DeanWhitehouse Posted August 23, 2008 Author Share Posted August 23, 2008 Thats what i have already. Quote Link to comment https://forums.phpfreaks.com/topic/121033-solved-am-i-using-trim-correctly/#findComment-623925 Share on other sites More sharing options...
DeanWhitehouse Posted August 23, 2008 Author Share Posted August 23, 2008 ok, solved, using string replace for anyone who wants it $name = htmlentities($_POST['dbhost']); $name = trim($name); $name = str_replace (" ", "", $name); Quote Link to comment https://forums.phpfreaks.com/topic/121033-solved-am-i-using-trim-correctly/#findComment-623927 Share on other sites More sharing options...
AjBaz100 Posted August 23, 2008 Share Posted August 23, 2008 Cool Quote Link to comment https://forums.phpfreaks.com/topic/121033-solved-am-i-using-trim-correctly/#findComment-623929 Share on other sites More sharing options...
DeanWhitehouse Posted August 23, 2008 Author Share Posted August 23, 2008 trust me , its the same thing. Quote Link to comment https://forums.phpfreaks.com/topic/121033-solved-am-i-using-trim-correctly/#findComment-623930 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.