Jump to content

Match end of string


TEENFRONT

Recommended Posts

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
Share on other sites

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
Share on other sites

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