CodeWriter Posted January 26, 2009 Share Posted January 26, 2009 The code adds a space after the $selleruser2 variable for some reason. Any help on this problem would be appreciated. $productsdb=file("Database/Usersfile.txt"); foreach($productsdb as $key1=>$val1) {$products[$key1]=explode("||",$val1);} for($k1=0;$k1<sizeof($productsdb);$k1++) { $selleruser2=$_POST["selleruser"]; if ($selleruser2==$products[$k1][0]) { echo "match"; } } Quote Link to comment https://forums.phpfreaks.com/topic/142417-if-statement-help/ Share on other sites More sharing options...
premiso Posted January 26, 2009 Share Posted January 26, 2009 Use trim. $selleruser2=trim($_POST["selleruser"]); Quote Link to comment https://forums.phpfreaks.com/topic/142417-if-statement-help/#findComment-746178 Share on other sites More sharing options...
.josh Posted January 26, 2009 Share Posted January 26, 2009 trim should work but fyi that code is not adding the space. Quote Link to comment https://forums.phpfreaks.com/topic/142417-if-statement-help/#findComment-746184 Share on other sites More sharing options...
CodeWriter Posted January 26, 2009 Author Share Posted January 26, 2009 Many thanks, it worked. Just curious though, what is adding the whitespace? Quote Link to comment https://forums.phpfreaks.com/topic/142417-if-statement-help/#findComment-746202 Share on other sites More sharing options...
.josh Posted January 26, 2009 Share Posted January 26, 2009 could be you (or user or whatever) entering it into the form. could be how you coded the form, perhaps with default values or something. Who knows? We can't begin to tell you without seeing that code. Quote Link to comment https://forums.phpfreaks.com/topic/142417-if-statement-help/#findComment-746234 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.