php version of pythons if in -


python has great: if sub-string in string, this:

if "fox" in "the quick brown fox jumps on lazy dog":    print true 

does php have equivalent this?

yes, see stripos , strpos

if(stripos("the quick brown fox jumps on lazy dog","fox")!==false)    { echo 'true'; } 

stripos , strpos return position @ match started, need use strict comparison (=== or !==) avoid false negative when needle @ pos. 0 in haystack.

you may prefer stristr, returns matched string or boolean false.

in_array works same in in python lists , dictionaries, if thinking beyond strings.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -