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

UserHex picture UserHex · Feb 3, 2013 · Viewed 20.1k times · Source

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

Answer

Frederik.L picture Frederik.L · Feb 3, 2013

You may use strpos directly.

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

Hope this help :)