What would be the most efficient way to check whether a string contains a "." or not?
I know you can do this in many different ways like with regular expressions or loop through the string to see if it contains a dot (".").
You can use stristr()
or strpos()
. Both return false if nothing is found.
You can use these string functions,
strstr — Find the first occurrence of a string
stristr — Case-insensitive strstr()
strrchr — Find the last occurrence of a character in a string
strpos — Find the position of the first occurrence of a substring in a string
strpbrk — Search a string for any of a set of characters
If that doesn't help then you should use preg
regular expression
preg_match — Perform a regular expression match
Source: Stackoverflow.com