2

I'am looking for a syntax that will do the following:

if('String' not in $string){

//do this

}

I am also looking for away to say

if('String' in $string){

//do this

}

Can anyone help, I have googled for solutions and they seem very confusing.

Thanks, J

1

2 Answers 2

7

I always use this:

if (stristr($string, "string")) {
    //String exists within $string
}else{
    //String does not exist
}

http://www.php.net/stristr

Sign up to request clarification or add additional context in comments.

Comments

3

Try this:

if(strpos($string, 'String') !== false) {
    //string exist
}
else{
    //string not exist
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.