PHP Tutorial 21 – Find If String Contains a String (PHP For Beginners)



The strpos(String Position) function will allow you to check if one string contains another string and will also determine the first occurrence of that string. This function has been very useful to me when parsing web pages and should prove useful for you too.

For more information, check out the website:

PHP Tutorial 21 Find If String Contains a String

23 thoughts on “PHP Tutorial 21 – Find If String Contains a String (PHP For Beginners)

  1. <?php

    // =

    // == equal

    // === identical

    /*

    $sentence = 'This is tutorial number 21';

    $needle = 'n';

    $search = strpos($sentence , $needle);

    if ($search === FALSE){

    echo 'The string was not found';

    } else {

    echo 'The position of the string is ' . $search ;

    }

    */

    $email = "[email protected]gmail.com";

    $needle = "n";

    $search = strpos($email, $needle);

    if ($search === FALSE)

    {

    echo 'This is not a valid email';

    } else {

    echo 'This is a valid email';

    }

    ?>

Leave a Reply

Your email address will not be published.