mike1313 Posted March 19, 2007 Share Posted March 19, 2007 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. Quote Link to comment Share on other sites More sharing options...
btherl Posted March 19, 2007 Share Posted March 19, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.