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... Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
bobleny Posted February 19, 2007 Author Share Posted February 19, 2007 What are regular expressions? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
bobleny Posted February 19, 2007 Author Share Posted February 19, 2007 Alright, thank you, this should work! Quote Link to comment 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! Quote Link to comment 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 } Quote Link to comment 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! 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.