Jump to content

string check


DuaneCawaling

Recommended Posts

$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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.