gergy008 Posted December 24, 2010 Share Posted December 24, 2010 Great alliteration in the title. *Ahem* Anyway I have this code that I use for my chat system, And I'm making a command system. However when I send the command, It picks it up as a command etc. but it is so stubborn it will not realise it. I'm guessing it's my human error again like usual but take a look, See if you can help me (Please note the filea() function is for debugging it's telling me where the code (by printing to file) is taking me as the way I'm using it I can't just use echo or print whatever and see the results on a page) if(substr($text, 0, 2)=="::"){ //the command trigger is :: filea("Picked up the start of the command"); $subt1=substr($text, 2); //seperate the command trigger, In my case :: to execute the command. filea("Just checking the string... ".$subt1); $comms=array('ban', 'mute', 'cls', 'sysm', 'unmute'); $match=false; foreach($comms as $comm){ $commtest2=strpos($subt1, $comm); if($comtest2!=false){ //I also tried ==true first with no success $match=true; $command=$comm; break; } } filea("Ran command checker"); if($match==false){ filea("Command not found match=".$match); exit; //Exit out if there were no matching commands. } When I run this command: ::mute test this is the log that gets given to me, As you can see from the code this is what I put in there. 3:07 AM) Logged in //this isn't in the code... (3:07 AM) Set text (3:07 AM) finding stats of person gergy008 (3:07 AM) Not muted. Continue... (3:07 AM) Has powers //up to here. But you don't need this. (3:07 AM) Picked up the start of the command (3:07 AM) Just checking the string... mute test (3:07 AM) Ran command checker (3:07 AM) Command not found match= As you can see I'm like -.- it's finding that the command is mute but it won't find mute in that string. It's dumb. Can someone help me find what the heck is wrong with this? I will be truely greatful Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/222554-strpos-stubbornness/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 24, 2010 Share Posted December 24, 2010 If you read the php.net documentation for strpos, you would learn why it is returning a zero(false) value when it finds the matching string starting in position zero and what logic test you would need to use to detect that vs an actual false value due to not finding the string. Quote Link to comment https://forums.phpfreaks.com/topic/222554-strpos-stubbornness/#findComment-1151001 Share on other sites More sharing options...
QuickOldCar Posted December 24, 2010 Share Posted December 24, 2010 I happened to notice a spelling mistake of yours. this: $commtest2=strpos($subt1, $comm); if($comtest2!=false){ should probably be: $commtest2=strpos($subt1, $comm); if($commtest2 != false){ was missing an m in $commtest2 Quote Link to comment https://forums.phpfreaks.com/topic/222554-strpos-stubbornness/#findComment-1151018 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.