How to check that one string contains another in PHP
If you want to check if one string contains desired string, you can use strpos function. But be aware - the problem rises when a needle is on position 0 of checked string. In that situation php strpos() returns 0, and it will return false if string is not found. So, to compare if a string is containing user string, use !== operator
if ( strpos( $string , 'somestring' ) !== false ) { }
Also use === false if you want to check that string doesn't not contains data
Comments
Post a Comment