In trying to figure out how to do it with preg_match, but I’m left with no clue. So what I’m trying is
$string = 'abc.hello.world.123.hola';
if ($string have 3 or more ".") {
echo 'true';
}
Advertisement
Answer
I know you said preg_match, but there is a specific PHP function for this. Use substr_count() 🙂
$string = 'abc.hello.world.123.hola';
$dots = substr_count($string, '.');
echo $dots; // output: 4
if ($dots >= 3) {
// do something
}