esbenp Posted February 2, 2010 Share Posted February 2, 2010 Hello, i have a wierd problem, or maybe i'm just too tired to se it for myself :-) $patterns = array( "firstname"=>"/^[A-Za-Z-æøå]{2,64} [A-Za-zæøå]?$/", "lastname"=>"/^[A-Za-zæøå-]{2,32}$/", "adress"=>"/^[A-Za-zæøå\.]{5,32} [0-9]{1,5} [A-Za-zæøå0-9\.]?$/", "city"=>"/^[A-Za-zæøå]{2,32}$/", "postnr"=>"/^[0-9]{4,4}$/", "tlf"=>"/^\+?[0-9]{8,10}$/", "email"=>"[A-Za-z0-9._]{2,32}@[A-Za-z0-9]{2,32}\.[A-Za-z]{2,5}" ); foreach($_POST as $key => $value) { if($key !== "shipping" || $key !== "payment" || $key !== "next_x" || $key !== "next_y") { if(preg_match($patterns[$key], $value)) { // do stuff.. } } } It keeps ignoring my || operators, and checks the "trash" of my $_POST array? Does anyone see why? And please comment on my patterns, if you'd like :-) Link to comment https://forums.phpfreaks.com/topic/190723-operator-wont-work/ Share on other sites More sharing options...
jl5501 Posted February 2, 2010 Share Posted February 2, 2010 I think you are falling into a common trap with or/not logic you say if any of the conditions are not true, then do the preg_match, and seeing as they cannot all be true, then it will always do the match. So I think your || should be && Link to comment https://forums.phpfreaks.com/topic/190723-operator-wont-work/#findComment-1005792 Share on other sites More sharing options...
RussellReal Posted February 2, 2010 Share Posted February 2, 2010 if (!in_array($key,array('shipping','payment','next_x','next_y'))) { } Link to comment https://forums.phpfreaks.com/topic/190723-operator-wont-work/#findComment-1005793 Share on other sites More sharing options...
esbenp Posted February 3, 2010 Author Share Posted February 3, 2010 Hmm.. I'm having a hard time seeing any logic in that, but it sure helped, thanks :-) Link to comment https://forums.phpfreaks.com/topic/190723-operator-wont-work/#findComment-1006080 Share on other sites More sharing options...
RussellReal Posted February 3, 2010 Share Posted February 3, 2010 Hmm.. I'm having a hard time seeing any logic in that, but it sure helped, thanks :-) in_array it returns true if the value is in the array, false otherwise. it just shortens if statements for me but it has many other uses Link to comment https://forums.phpfreaks.com/topic/190723-operator-wont-work/#findComment-1006300 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.