Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP if not in string [duplicate]

Tags:

syntax

php

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

like image 600
user1269625 Avatar asked Mar 18 '26 17:03

user1269625


1 Answers

I always use this:

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

http://www.php.net/stristr

like image 50
James Avatar answered Mar 20 '26 09:03

James



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!