I want to know if the string contains two .
. for example if the string contains www.example.com
, returns true ,because it has 2 .
, otherwise has less than 1 .
return false.
function containsTwoDot($array,$keyword){
$matches = array_filter($array, function($var) use ($keyword) { return preg_match("/\b".$keyword."\b/i".$keyword, $var); });
if($matches)
return true;
return FALSE;
}
$true[0]='www.sll.dl';
$false[0]='ldfjls.dlfjdflldl';
You can use php function substr_count()
-
<?php
$text = 'www.example.com';
echo substr_count($text, '.'); // 2
?>
of course it doesn't return true or false .That you can manage.
Use preg_match and escape dots cause it's special chars:
$string = 'www.example.com';
preg_match('/\..*\./',$string);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.