ILYAS415 Posted February 19, 2008 Share Posted February 19, 2008 Okay i'm making a chat room thing and i would like to know how check if the user has entered a certain word into his her string. Basically im trying to make a /me commad (the typical action command). I have already tried using this.... strpos("/me", $string, 1); however that means that the user can enter in.... wow the /me command is wicked and if will be seen as an action command because it got /me inside it. I only want the script to look for /me if it is in the beggining of a sentance. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 19, 2008 Share Posted February 19, 2008 preg_match('{word}','text'); maybe? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 19, 2008 Share Posted February 19, 2008 good plan is BB tags you can use them to apply basic styling, and you can probably get your desired affect from it. Quote Link to comment Share on other sites More sharing options...
Barand Posted February 19, 2008 Share Posted February 19, 2008 <?php if (strpos($string, "/me") === 0) { // its at the beginning } ?> Quote Link to comment Share on other sites More sharing options...
ILYAS415 Posted February 19, 2008 Author Share Posted February 19, 2008 Barand your code didnt appear to work for me. phpSensai im not sure how exactly to use the function your gave me. Can you please give me a snippet based on the example i gave? hmm im considering bbcodes as my last option. Quote Link to comment Share on other sites More sharing options...
Barand Posted February 19, 2008 Share Posted February 19, 2008 <?php $string = '/me foo bar'; if (strpos($string, "/me") === 0) { echo 'its at the beginning'; } else { echo 'Oh no its not'; } ?> Quote Link to comment Share on other sites More sharing options...
ILYAS415 Posted February 19, 2008 Author Share Posted February 19, 2008 Nope not working... :S heres my code im using... if (strpos($msg, "/me") === "0"){ $msg= str_replace("/me", "", $msg); $out="$chattext ".ucfirst($fetch->username)." <font color=white>$msg</font><br>"; }else{ $out = $chattext . $n . " - " . $msg . "<br>"; $out = str_replace("\'", "'", $out); $out = str_replace("\\\"", "\"", $out); } $out= chat($out); Thanks again Quote Link to comment Share on other sites More sharing options...
Barand Posted February 19, 2008 Share Posted February 19, 2008 Lose the quotes round the 0 if (strpos($msg, "/me") === "0") Quote Link to comment Share on other sites More sharing options...
ILYAS415 Posted February 19, 2008 Author Share Posted February 19, 2008 Nope still not working :S comes out as.... Ilyas415 - /me message here instead of ilyas415 message here Quote Link to comment Share on other sites More sharing options...
Barand Posted February 19, 2008 Share Posted February 19, 2008 Don't have $fetch object so I changed $fetch->username to $username. Also don't have you chat() function, but <?php $username = 'xyz'; $msg = '/me foo bar'; $chattext = 'abc'; if (strpos($msg, "/me") === 0){ $msg= str_replace("/me", "", $msg); $out="$chattext ".ucfirst($username)." <font color=white>$msg</font><br>"; }else{ $out = $chattext . $n . " - " . $msg . "<br>"; $out = str_replace("\'", "'", $out); $out = str_replace("\\\"", "\"", $out); } echo $out; // --> abc Xyz <font color=white> foo bar</font><br> ?> Quote Link to comment Share on other sites More sharing options...
BrandonK Posted February 20, 2008 Share Posted February 20, 2008 what if the person is using /me in more than one spot -- perhaps explaining how to use /me: [/me things that you do an emote you simply say "/me emote"] Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 20, 2008 Share Posted February 20, 2008 thus why I said use bbCode 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.