-
-
qq_深秋那血紅的黃昏_0
2017-04-24
- //切换返回数据的类型
public function toggleReturnType($bool=null){
if (empty($bool)) {
$this->returnMatchResult = !$this->returnMatchResult;
}else{
$this->returnMatchResult = is_bool($bool)?$bool:(bool)$bool;
}
}
//修改修正模式
public function setFixMode($fixMode){
$this->fixMode = $fixMode;
}
-
1赞 · 0采集
-
-
异常代码
2016-11-08
- Preg_match_all
-
0赞 · 0采集
-
-
异常代码
2016-11-08
- Array_key_exists
-
0赞 · 0采集
-
-
_Linl
2016-09-12
- /** 匹配方法
* $pattern 参数一: 正则表达式
* $subject 参数二: 需要匹配的目标字符串
* 返回值: 首先判断需要返回的是那种类型的结果,
* 如果需要返回匹配结果数组,就调用preg_match_all方法,并把结果放入matches数组里面
* 否则就调用preg_match方法,结果isMatch的值就是preg_match的返回值是否恒等于1,也即是是否匹配到了。
*/
private function regex($pattern,$subject){
if (array_key_exists(strtolower($pattern),$this->validate)){
$pattern = $this->validate[$pattern].$this->fixMode;
}
$this->returnMatchResult ? preg_match_all($pattern,$subject,$this->matches):$this->isMatch = preg_match($pattern,$subject) === 1;
return $this->getRegexResult();
}
/** 返回结果的方法
* 判断returnMatchResult 是哪种(结果数组还是是否匹配的bool值)
*/
private function getRegexResult(){
if ($this->returnMatchResult){
return $this->matches;
}else {
return $this->isMatch;
}
}
-
1赞 · 1采集
-
-
_Linl
2016-09-12
- /** 需要的结果是全部匹配还是是否匹配 -- 返回结果的数组还是布尔值*/<br>
private $returnMatchResult = false;<br>
/** 修正模式*/<br>
private $fixMode = null;<br>
/** 返回的匹配结果数组*/<br>
private $matches = array();<br>
/** 返回的匹配结果(是否匹配)*/<br>
private $isMatch = false;<br>
<br>
/** 构造函数,本工具供外部调用的构造方法,<br>
* $returnMatchResult 参数一: 外部告诉本方法需要返回的结果类型(是数组还是布尔值) 默认为false,如果不传入,默认为是false<br>
* $fixMode 参数二: 外部输入的修正模式 如果不传入,默认为null<br>
*/<br>
public function __construct($returnMatchResult=false,$fixMode=null)<br>
{<br>
$this->returnMatchResult = $returnMatchResult;<br>
$this->fixMode = $fixMode;<br>
}
-
1赞 · 1采集
-
-
12222
2016-03-20
- 3333
-
0赞 · 0采集
-
-
frozen_flower
2015-11-06
- 修改模式
-
截图
0赞 · 1采集
-
-
frozen_flower
2015-11-06
- 构造方法
-
截图
0赞 · 1采集
-
-
Seek_Era
2015-10-27
- 还没理解
-
0赞 · 0采集
-
-
林静听蝉
2015-09-23
- private function regex($pattern,$subject){
if(array_key_exists(strtolower($pattern), $this->validate)){
$pattern = $this->validate[$pattern].$this->fixMode;}
$this->returnMatchResult ? preg_match_all($pattern,$subject,$this->$matches) : $this->isMatch = preg_match($pattern,$subject) === 1;
return $this->getRegexResult();}
private function getRegexResult(){
if($this->returnMatchResult){
return $this->matches;
}else{return $this->isMatch;}}
public function toggleReturnType($bool = null){
if(empty($bool)){
$this->returnMatchResult = !$this->returnMatchResult;}else{
$this->returnMatchResult = is_bool($bool) ? $bool : (bool)$bool;}}
public function setFixMode($fixMode){$this->fixMode = $fixMode;}
-
截图
0赞 · 2采集
-
-
恋高三
2015-09-13
- array_key_exists():检查数组中是否存在键
-
截图
0赞 · 0采集
-
-
Aidcat
2015-05-20
- regexTool.class.php (3)
//设置修正模式
public function setFixMode($fixMode) {
$this->fixMode = $fixMode;
}
//用户名必须填写
public function noEmpty($str) {
return $this->regex('require', $str);
}
//邮箱格式
public function isEmail($email) {
return $this->regex('email', $email);
}
//手机号格式
public function isMobile($mobile) {
return $this->regex('mobile', $mobile);
}
public function check($pattern, $subject) {
return $this->regex($pattern, $subject);
}
}
-
0赞 · 0采集
-
-
Aidcat
2015-05-20
- regexTool.class.php (2)
private function regex($pattern, $subject) {
//检测内置正则表达式中是否已经存在
//strlower()将字符转化为小写,防止意外错误
if(array_key_exists(strtolower($pattern), $this->validate)){
$pattern = $this->validate[$pattern].$this->fixMode;
}
//对返回的类型进行定义,如果返回的属性是真,则进行一个匹配,并且把结果放在定义的matches数组中,否则使用preg_match进行一个验证
$this->returnMatchResult ?preg_match_all($pattern, $subject, $this->matches) :$this->isMatch = preg_match($pattern, $subject) === 1;
return $this->getRegexResult();
}
//对验证的结果进行返回
private function getRegexResult() {
if($this->returnMatchResult) {
return $this->matches;
} else {
return $this->isMatch;
}
}
//切换返回类型
public function toggleReturnType($bool = null) {
if(empty($bool)) {
//直接切换真假的状态
$this->returnMatchResult = !$this->returnMatchResult;
} else {
$this->returnMatchResult = is_bool($bool) ? $bool : (bool)$bool;
}
}
-
0赞 · 0采集
-
-
Aidcat
2015-05-20
- regexTool.class.php (1)
<?php
class regexTool {
//内置一些常用的正则表达式
private $validate = array(
'require' => '/.+/',
'email' => '/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',
'url' => '/^http(s?):\/\/(?:[A-za-z0-9-]+\.)+[A-za-z]{2,4}(?:[\/\?#][\/=\?%\-&~`@[\]\':+!\.#\w]*)?$/',
'currency' => '/^\d+(\.\d+)?$/',
'number' => '/^\d+$/',
'zip' => '/^\d{6}$/',
'integer' => '/^[-\+]?\d+$/',
'double' => '/^[-\+]?\d+(\.\d+)?$/',
'english' => '/^[A-Za-z]+$/',
'qq' => '/^\d{5,11}$/',
'mobile' => '/^1(3|4|5|7|8)\d{9}$/',
);
//定义返回的结果,false时只返回验证结果真还是假,如果为true返回数组
private $returnMatchResult = false;
//修正模式默认为空
private $fixMode = null;
//匹配的数组
private $matches = array();
//验证结果
private $isMatch = false;
//定义一个构造函数,fixMode为修正参数
public function __construct($returnMatchResult = false, $fixMode = null) {
$this->returnMatchResult = $returnMatchResult;
$this->fixMode = $fixMode;
}
-
0赞 · 0采集
-
-
陈校军
2015-05-16
- Important!! 功能类的构造形式…
-
0赞 · 0采集