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 Link to comment https://forums.phpfreaks.com/topic/201529-what-does-this-actually-do/ 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 Link to comment https://forums.phpfreaks.com/topic/201529-what-does-this-actually-do/#findComment-1057289 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. Link to comment https://forums.phpfreaks.com/topic/201529-what-does-this-actually-do/#findComment-1057293 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 Link to comment https://forums.phpfreaks.com/topic/201529-what-does-this-actually-do/#findComment-1057295 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. Link to comment https://forums.phpfreaks.com/topic/201529-what-does-this-actually-do/#findComment-1057296 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.