PHP Check if String Contains Substring

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
    }

All PHP Scripts on this website are provided by phpscripts4u.com where you can find all the latest PHP code snippets, plugins and libraries.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>