How to find string within string in PHP? Checking for existence of a string (or substring) inside another string is easier than it might seem. The following code snippet shows how to check for whether a string contains string in PHP.
$intPos = strpos($strHaystack,$strNeedle);
if( $intPos === false ) {
// string strNeedle NOT found in strHaystack
} else {
// string strNeedle found in strHaystack
}
if( $intPos === false ) {
// string strNeedle NOT found in strHaystack
} else {
// string strNeedle found in strHaystack
}
All PHP Scripts on this website are provided by phpscripts4u.com where you can find all the latest PHP code snippets, plugins and libraries.