Tuesday, 15 June 2010

php - AJAX chat commands - if command doesn't exist, echo error -


I have these command handling:

$ message = entered message

  Public function handle comand ($ message, $ user name) {// variable which we are going to use $ space = strpos ($ message, ''); # First place $ command = trim (substr ($ message, 1, $ location)); # Slash $ name = substr ($ message, $ space + 1) command; # Name after the order Switch ($ command) {case 'ban': $ this- & gt; Restriction ($ name, $ user name); break; Case 'prune': $ this- & gt; Redemption ($ username); break; Case '': echo 'please use an order!'; break; Case 'test': {$ this-> Try the exam ($ name); } Hold (exception $ r) {echo $ r- & gt; GetMessage (); } break; }}   

This will basically check the command.

The words given after $ command = slash ("/").

You can see that

  case:   

It basically checks that there is no order after the slash.

Question: I want the system to be checked, if the command exists in the case. For example:

User wrote:

/ Hello

But this command is not present, consider that We have only 'ban', case 'prune', 'trial' and 'case'.

There is no case 'hello', so it will throw an error. Is there any such thing which does this kind of thing? How can I do this?

I believe what you want is a default: case .

Example:

  & lt ;? Php switch ($ i) {case 0: echo "i is equal 0"; break; Case 1: The echo "I am equal to 1"; break; Case 2: Echo "I equal 2"; break; Default: Echo "is not equal to ii, 1 or 2"; }? & Gt;   

Edit : Fixed version of the problem about which was spoken:

No comments:

Post a Comment