strategos Posted January 17, 2012 Share Posted January 17, 2012 This should be simple. However, when I run the script and input a say 18 char long string, it still returns -10. The variable char_total is accurately capturing the string length. <?php $inputid = $_POST['steamid']; $steam_prefix = substr($inputid, 0, 10); $prefix_length = 10; $steam_suffixchars = ($char_total - $prefix_length); $char_total = strlen($inputid); if($char_total > 25 || $char_total < 11) $char_valid = false; else $char_valid = true; if($steam_prefix === "STEAM_0:1:" || $steam_prefix === "STEAM_0:0:") $prefix_check = true; elseif($steam_prefix != "STEAM_0:1:" || $steam_prefix != "STEAM_0:0:") $prefix_check = false; echo "$steam_suffixchars" ?> Quote Link to comment https://forums.phpfreaks.com/topic/255200-php-subtraction-error/ Share on other sites More sharing options...
MasterACE14 Posted January 17, 2012 Share Posted January 17, 2012 if you know the prefix is a fixed length, why wouldn't you just check what the user inputs? Quote Link to comment https://forums.phpfreaks.com/topic/255200-php-subtraction-error/#findComment-1308460 Share on other sites More sharing options...
Proletarian Posted January 17, 2012 Share Posted January 17, 2012 Instead of... $prefix_length = 10; $steam_suffixchars = ($char_total - $prefix_length); $char_total = strlen($inputid); ...try... $prefix_length = 10; $char_total = strlen($inputid); $steam_suffixchars = ($char_total - $prefix_length); Quote Link to comment https://forums.phpfreaks.com/topic/255200-php-subtraction-error/#findComment-1308470 Share on other sites More sharing options...
strategos Posted January 17, 2012 Author Share Posted January 17, 2012 if you know the prefix is a fixed length, why wouldn't you just check what the user inputs? I need to check with prefix to see if it is valid then check the suffix which only consists of inegers. After I get the subtraction right, I was going to run substr() to compare the suffix with is_int() Quote Link to comment https://forums.phpfreaks.com/topic/255200-php-subtraction-error/#findComment-1308579 Share on other sites More sharing options...
strategos Posted January 17, 2012 Author Share Posted January 17, 2012 Ah I never thought to try that, but it worked! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/255200-php-subtraction-error/#findComment-1308639 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.