Jump to content

[SOLVED] Help Please


mike1313

Recommended Posts

I've written a simple chatroom for my website. But I want to know how I can make it so if the user types a certain command, that a certain table in the MySql DB can be updated and it doesnt display anything on the page. For example if they wanted to change the color of their font in the chat, they would type /hexcode #FFFFFF

 

and it would find them in the db and under the field chatfont it would change it to #FFFFFF, I know everything about updating the DB and so forth all I need is what I should use for the line of code to check to see if they posted at least /hexcode and it gets rid of /hexcode and just updates the db with #FFFFFF all help is appreciated thanks.

Link to comment
Share on other sites

How about this:

 

$command = trim(urldecode($_POST['command']));
if (strpos($command, '/hexcode') === 0) {
  # We found /hexcode at offset 0
  $colour = preg_replace('|/hexcode *|', '', $command);
  # Then update the db with $colour
}

 

There's many other ways to do it.. if you have many commands to detect, you may want to start by checking if '/' is at the start, and only then parsing the command.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.