[英]how to find if a string contains two dot in regular expression in php
I want to know if the string contains two .
我想知道字符串是否包含两个
.
. 。 for example if the string contains
www.example.com
, returns true ,because it has 2 .
例如,如果字符串包含
www.example.com
,则返回true,因为它具有2 .
, otherwise has less than 1 .
,否则小于1
.
return false. 返回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函数
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: 使用preg_match和转义点导致它的特殊字符:
$string = 'www.example.com';
preg_match('/\..*\./',$string);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.