otuatail Posted March 30, 2010 Share Posted March 30, 2010 Can anyone tell me if there is a function to check if a number is hex-decimal. For security reasons, I am using hex and md5() which produces a 32 character hex value. This might be require a regx expression but not good at regx. Thanks. Desmond. Link to comment https://forums.phpfreaks.com/topic/196978-is-number-hex-problem/ Share on other sites More sharing options...
salathe Posted March 30, 2010 Share Posted March 30, 2010 You can use ctype_xdigit to check for only hex characters and then also check that the string is 32 characters long. if (ctype_xdigit($md5) && strlen($md5) === 32) { // Yay } Link to comment https://forums.phpfreaks.com/topic/196978-is-number-hex-problem/#findComment-1034100 Share on other sites More sharing options...
otuatail Posted March 30, 2010 Author Share Posted March 30, 2010 thanks. Bit confused over the extra = iv === 32 Desmond Link to comment https://forums.phpfreaks.com/topic/196978-is-number-hex-problem/#findComment-1034128 Share on other sites More sharing options...
runnerjp Posted March 30, 2010 Share Posted March 30, 2010 typo i belive... should be if (ctype_xdigit($md5) && strlen($md5) == 32) { // Yay} just shing is the code equal to 32 char (strlen) long Link to comment https://forums.phpfreaks.com/topic/196978-is-number-hex-problem/#findComment-1034130 Share on other sites More sharing options...
otuatail Posted March 30, 2010 Author Share Posted March 30, 2010 Ok thanks for that. Good work Desmond. Link to comment https://forums.phpfreaks.com/topic/196978-is-number-hex-problem/#findComment-1034132 Share on other sites More sharing options...
Adam Posted March 30, 2010 Share Posted March 30, 2010 It's not a typo. "===" performs an 'identical' comparison, meaning it compares the data type too. http://php.net/manual/en/language.operators.comparison.php Link to comment https://forums.phpfreaks.com/topic/196978-is-number-hex-problem/#findComment-1034134 Share on other sites More sharing options...
salathe Posted March 30, 2010 Share Posted March 30, 2010 typo i belive... should be Not a typo at all. As Mr Adam said, it's the identical comparison operator. Link to comment https://forums.phpfreaks.com/topic/196978-is-number-hex-problem/#findComment-1034217 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.