how to check if '.'[dot] is present in string or not ? strstr is not working in php

21,778

You may use strpos directly.

if (strpos($mystring, ".") !== false) {
    //...
}

Hope this help :)

Share:
21,778
UserHex
Author by

UserHex

Updated on July 05, 2022

Comments

  • UserHex
    UserHex almost 2 years

    I am trying to see if . [dot] is present in string or not.

    I have tried strstr but it returns false.

    here is my code :-

    <?php
    $str = strpos("true.story.bro", '.');
    if($str === true)
    {
            echo "OK";
    } else {
            echo "No";
    }
    ?>
    

    I want to see if '.' is present in string or not, I can do with explode, but i want to do in 1 line, how could i do that ?

    Thanks

  • Frederik.L
    Frederik.L about 11 years
    You're welcome! In fact, strpos is a "confused?" int that return false if the needle part is not present in the sentence. Just pay attention to the operator !== that validate the type of strpos, as != could also make this true if strpos return an int that can be equivalent to FALSE, which would be an error.