TeddyKiller Posted May 12, 2010 Share Posted May 12, 2010 Small code. Little reply. $alpha_num = str_replace(" ", "", $username); if (!ctype_alnum($alpha_num)) : return 2; endif; What does it do? Thanks Quote Link to comment Share on other sites More sharing options...
Lamez Posted May 12, 2010 Share Posted May 12, 2010 I think it checks to see if the string contains any letters or digits. If it does not, it returns 2 Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted May 12, 2010 Author Share Posted May 12, 2010 Isn't $alpha_num = str_replace(" ", "", $username); equivalent to $alpha_num = trim($username); So if ctype_alnum() checks if the string is alphabetic and/or numeric... is it an old function? Has it been deprecated? Never seen it used before. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 12, 2010 Share Posted May 12, 2010 No, it's not the same as using trim. The str_replace removes all spaces from the string, not just the ones before/after like trim(). Ken Quote Link to comment Share on other sites More sharing options...
Lamez Posted May 12, 2010 Share Posted May 12, 2010 Not sure on the trim function, but the first line takes out the spaces of the string and mashes it all into one for easier checking. See the manual for the second function: http://php.net/manual/en/function.ctype-alnum.php I've used it before, can't remember for what. Quote Link to comment 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.