if ( strpos( $string , 'somestring' ) !== false ) {
}
Also use === false if you want to check that string doesn't not contains data
PHP Coding tips & tricks. Function & error explanation, coding style, how tos etc. Short notes posted directly from developer work environment.
PHP Coding Tips
Wednesday, August 8, 2012
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
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment