For my game I’m coding a console that sends messages via AJAX and then receives output from the server.
For example, an input would be:
/testmessage Hello!
However, I would also need to parse the quotes e.g.:
/testmessage "Hello World!"
However, since I am simply exploding the string with spaces, PHP sees "Hello and World!" as separate parameters. How do I make PHP think that “Hello World!” is one parameter?
Right now I’m using the following code to parse the command:
// Suppose $inputstring = '/testmessage "Hello World!"';
$inputstring = substr($inputstring, 1);
$parameters = explode(" ", $inputstring);
$command = strtolower($parameters[0]);
switch ($command) {
case "testmessage":
ConsoleDie($parameters[1]);
break;
}
Thank you in advance.
This code will do what you want:
that print:
Note: As you can see the first parameter is the command