DuaneCawaling Posted March 6, 2013 Share Posted March 6, 2013 $str= "WAL bal"; $message = explode(" ",$word); if(preg_match('/(register|bal|menu|snacks|drinks|buy|pass)/', $str)){ if($message[1]){ echo "KEYWORD--OK <br>"; return $str; }else echo "Invalid keyword, try again."; this works okay, the only problem is that if $str = WAL balance, it is still strue coz it has "bal" and i dont want that to happen.. what can i do to limit the $message[1] as such register|bal|menu|snacks|drinks|buy|pass ONLY?? Link to comment https://forums.phpfreaks.com/topic/275297-string-check/ Share on other sites More sharing options...
requinix Posted March 6, 2013 Share Posted March 6, 2013 Why use regular expressions at all? in_array does what you (apparently) need. Link to comment https://forums.phpfreaks.com/topic/275297-string-check/#findComment-1416861 Share on other sites More sharing options...
DuaneCawaling Posted March 6, 2013 Author Share Posted March 6, 2013 the $str is a string. in_array() needs an array as a parameter. to make the string an array.str_split is used. a problem occurs because the string's parameters 'register|bal|menu|snacks|drinks|buy|pass' are not equal in length.str_split arrays with equal length Link to comment https://forums.phpfreaks.com/topic/275297-string-check/#findComment-1416872 Share on other sites More sharing options...
requinix Posted March 6, 2013 Share Posted March 6, 2013 Right. But you could just put them in an array instead of a string: $words = array("register", "bal", "menu", "etc");[edit] And even if you didn't want to do that, you would have to use explode() (which you've shown you know about) not str_split(). Link to comment https://forums.phpfreaks.com/topic/275297-string-check/#findComment-1416875 Share on other sites More sharing options...
DuaneCawaling Posted March 6, 2013 Author Share Posted March 6, 2013 i did not think of that..sorry for that..anyways thank you for the advice it works perfectly fine now Link to comment https://forums.phpfreaks.com/topic/275297-string-check/#findComment-1416893 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.