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
The easiest way is to check with a . contains() statement. Note: . contains() works only for strings.
Answer: Use the PHP strpos() Function You can use the PHP strpos() function to check whether a string contains a specific word or not. The strpos() function returns the position of the first occurrence of a substring in a string. If the substring is not found it returns false .
To check if a string doesn't include a substring, call to the indexOf() method on the string, passing it the substring as a parameter. If the indexOf method returns -1 , then the substring is not contained in the string.
The is_string() function checks whether a variable is of type string or not. This function returns true (1) if the variable is of type string, otherwise it returns false/nothing.
You may use strpos directly.
if (strpos($mystring, ".") !== false) {
//...
}
Hope this help :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With