bobleny Posted February 19, 2007 Share Posted February 19, 2007 How can I check $_POST['monkeys'] for the number of characters and what characters it contains? I want to run scripts against their inputs... Link to comment https://forums.phpfreaks.com/topic/39224-solved-how-can-i-check-user-input/ Share on other sites More sharing options...
hitman6003 Posted February 19, 2007 Share Posted February 19, 2007 strlen and strpos http://www.php.net/strlen http://www.php.net/strpos Link to comment https://forums.phpfreaks.com/topic/39224-solved-how-can-i-check-user-input/#findComment-188989 Share on other sites More sharing options...
effigy Posted February 19, 2007 Share Posted February 19, 2007 Regular expressions are handy for performing advanced checks, if needed. See the links in my signature. Link to comment https://forums.phpfreaks.com/topic/39224-solved-how-can-i-check-user-input/#findComment-188995 Share on other sites More sharing options...
bobleny Posted February 19, 2007 Author Share Posted February 19, 2007 What are regular expressions? Link to comment https://forums.phpfreaks.com/topic/39224-solved-how-can-i-check-user-input/#findComment-188997 Share on other sites More sharing options...
effigy Posted February 19, 2007 Share Posted February 19, 2007 What are regular expressions? See the links in my signature. One of those links: Tutorial P.S. We have a Regex Board. Link to comment https://forums.phpfreaks.com/topic/39224-solved-how-can-i-check-user-input/#findComment-189000 Share on other sites More sharing options...
roopurt18 Posted February 19, 2007 Share Posted February 19, 2007 Your first encounter with regular expressions is like falling into the lion exhibit at the zoo 15 minutes before the lions' regular feeding time. Once you get familiar with them, your relationship with regexps is a lot like Siegfried and Roy's relationship with their tigers. Usually you can get them to do what you want, you can even bully them a little, but it's only a matter of time before one eats you. That said, regexps are a powerful string pattern-matching tool. Honestly, you can't live without them. Link to comment https://forums.phpfreaks.com/topic/39224-solved-how-can-i-check-user-input/#findComment-189002 Share on other sites More sharing options...
bobleny Posted February 19, 2007 Author Share Posted February 19, 2007 strlen and strpos should work fine for what I am doing. Once I find a character, how do I replace it? Link to comment https://forums.phpfreaks.com/topic/39224-solved-how-can-i-check-user-input/#findComment-189010 Share on other sites More sharing options...
effigy Posted February 19, 2007 Share Posted February 19, 2007 str_replace. Please see the String Functions in the manual. Link to comment https://forums.phpfreaks.com/topic/39224-solved-how-can-i-check-user-input/#findComment-189015 Share on other sites More sharing options...
bobleny Posted February 19, 2007 Author Share Posted February 19, 2007 Alright, thank you, this should work! Link to comment https://forums.phpfreaks.com/topic/39224-solved-how-can-i-check-user-input/#findComment-189021 Share on other sites More sharing options...
bobleny Posted February 19, 2007 Author Share Posted February 19, 2007 Wait, let me ask another question on this.... $monkeys, may only contain letters and or numbers with no spaces. $pass = strpos($monkeys, $legal); if($pass === FALSE) { everything is good } else { $monkeys isn't alphanumeric } What should $legal be? I got no idea how to do this... Thanks! Link to comment https://forums.phpfreaks.com/topic/39224-solved-how-can-i-check-user-input/#findComment-189067 Share on other sites More sharing options...
effigy Posted February 20, 2007 Share Posted February 20, 2007 The simplest way to check this is with regular expressions: if (preg_match('/^[A-Za-z0-9]+\z/', $monkeys)) { // is valid } else { // is not valid } Link to comment https://forums.phpfreaks.com/topic/39224-solved-how-can-i-check-user-input/#findComment-189212 Share on other sites More sharing options...
bobleny Posted February 20, 2007 Author Share Posted February 20, 2007 Regular expressions, huh? That figures... I guess I'll have to read up on that.... Alright then. Thanks a lot! Link to comment https://forums.phpfreaks.com/topic/39224-solved-how-can-i-check-user-input/#findComment-189503 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.