TEENFRONT Posted July 10, 2009 Share Posted July 10, 2009 Hey i have a string thats, example $string = "Kick user XXXXXXXXXXXX"; XXXXXXXX could be anything (in this case its a user ID but can be anything) How can i see if string has "kick user" in it. im using it in an if statement like this if($message = "ban user" || $message == "kick user xxxxxxx") but as said, the xxxx could be anything so it wont match. any help? Link to comment https://forums.phpfreaks.com/topic/165440-match-end-of-string/ Share on other sites More sharing options...
BMurtagh Posted July 10, 2009 Share Posted July 10, 2009 Hey there, You'll wanna take a look at the PHP strstr() function for this. I'm including a little code example to get you going, but the best resource for learning about the function is at: http://www.php.net/manual/en/function.strstr.php <?php // get last directory in $PATH $text = "dude wheres my car user"; $test = "kick user dsdf3243221sad"; // get everything after last newline if (strstr($test, "kick user")) echo "true"; else echo "false"; ?> Link to comment https://forums.phpfreaks.com/topic/165440-match-end-of-string/#findComment-872590 Share on other sites More sharing options...
TEENFRONT Posted July 10, 2009 Author Share Posted July 10, 2009 Perfect mate thanks!! Erm, another quickie, how would i then pull userid from the string? just explode() the spaces? then use $exploded[2] ? or is there a better way? Link to comment https://forums.phpfreaks.com/topic/165440-match-end-of-string/#findComment-872596 Share on other sites More sharing options...
joel24 Posted July 10, 2009 Share Posted July 10, 2009 explode[2] would work alrite, or you could use some of the string functions and get rid of "kick user" leaving you the id... what are you trying to do here? might be an idea to store it in an array.. i.e. $test[1] = "kick user"; $test[2] = "userID"; ...? Link to comment https://forums.phpfreaks.com/topic/165440-match-end-of-string/#findComment-872597 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.