protected function checkField($field, $value, $rule, $prompt, $extra = '', $extend = '') { $result = true; switch ($rule) { case 'unique': $obj = M($extra); $where = $field . '=\'' . $value . '\''; if ($extend != '') { $where .= ' and ' . $extend; } $data = $obj->where($where)->find(); $data = deep_htmlspecialchars_decode($data); if ($data != '') { $result = false; } break; case 'uniform': if ($field != $value) { $result = false; } break; default: $result = regex($value, $rule); } if (!$result) { $this->error($prompt); } }
function magicSplit($regex, $string) { $pieces = preg_split(regex('(?:(?&string)|(?&comment)|(?&code))(*SKIP)(*FAIL)|' . $regex), $string); foreach ($pieces as &$piece) { $piece = trim($piece); } return array_filter($pieces); }
/** * Create a new Bot instance. * * @param array $tree */ public function __construct($tree) { $this->tree = $tree; $this->pattern = regex()->find('<bot ')->anythingBut('>')->asGroup()->then('>')->getRegExp(); }
public function handlePasswdAction() { Yaf_Dispatcher::getInstance()->disableView(); if ($this->getRequest()->isGet()) { $this->notify("页面不存在"); die; } $old_passwd = $this->getPost("old_passwd", false); $new_passwd = $this->getPost("new_passwd", false); $re_passwd = $this->getPost("re_passwd", false); if (!regex($old_passwd, "require")) { $this->notify("旧密码不能为空.."); die; } $session_uid = $this->getSession("uid"); $user_info = $this->m_user->Where("id=" . $session_uid)->Field("id,password")->SelectOne(); if ($user_info["password"] != md5($old_passwd)) { $this->notify("旧密码不正确.."); die; } if (!regex($new_passwd, "require")) { $this->notify("新密码不能为空.."); die; } if (!regex($re_passwd, "require")) { $this->notify("确认密码不能为空.."); die; } if (!regex($new_passwd, "six")) { $this->notify("新密码必须6-18位"); die; } if ($new_passwd != $re_passwd) { $this->notify("新密码和确认密码不一致"); die; } $tmp_data = array(); $tmp_data["password"] = md5($new_passwd); $result = $this->m_user->UpdateByID($tmp_data, $user_info["id"]); if ($result) { $this->notify("修改密码成功..", "/member/passwd", "success"); die; } else { $this->notify("修改密码失败..."); die; } }
function magicSplit($regex, $string) { $pieces = preg_split(regex('(?:(?&string)|(?&comment)|(?&code))(*SKIP)(*FAIL)|' . $regex), $string); foreach ($pieces as &$piece) { $piece = trim($piece); } if ($pieces === ['']) { return []; } return $pieces; }
function parse_property($document) { $properties = $document->find(PROPERTY_FINDER); echo "FOUND " . count($properties) . " PROPERTIES\n"; foreach ($properties as $property) { $property_data = array(); $main_link = $property->find(MAIN_LINK_FINDER, 0); $property_data['zip'] = regex(ZIPCODE_REGEX, $main_link->href); $property_data['address'] = $main_link->plaintext; echo "FOUND: {$property_data['address']}\n"; $property_data['price'] = str_replace(array('$', ','), '', $property->find(SALE_PRICE_FINDER, 0)->plaintext); $data_table = $property->find(DATA_TABLE_FINDER, 0)->plaintext; $data_table2 = $property->find(DATA2_TABLE_FINDER, 0)->plaintext; $value = regex(BEDROOM_REGEX, $data_table); $property_data['bed'] = $value == '--' ? 0 : $value + 0; $value = regex(BATHROOM_REGEX, $data_table); $property_data['bath'] = $value == '--' ? 0 : $value + 0; $value = regex(SQUAREFOOT_REGEX, $data_table); $property_data['sqft'] = $value == '--' ? 0 : str_replace(',', '', $value) + 0; $value = regex(LOTSIZE_REGEX, $data_table); $property_data['lot'] = $value == '--' ? 0 : str_replace(',', '', $value) + 0; $value = regex(LISTED_REGEX, $data_table2) + 0; $property_data['listed'] = date('Y-m-d', strtotime("{$value} days ago")); $value = regex(BUILT_REGEX, $data_table2); $property_data['built'] = $value == '--' ? '' : $value; $value = regex(PROP_TYPE_REGEX, $data_table2); $property_data['type'] = $value; $property_data['res'] = FALSE; if ($property_data['bed'] != 0 && $property_data['sqft'] != 0) { $property_data['res'] = TRUE; } writeData($property_data); } }
/** * * Enter description here... * @param $pattern * @param $startPosition * @param $flags * @return unknown_type */ public function match($pattern, $startPosition = 0, $flags = null) { return regex($pattern)->match($this->value, $startPosition, $flags); }
/** * 获取输入参数 支持过滤和默认值 * * @param string $name 变量的名称 支持指定类型 * @param mixed $default 不存在的时候默认值 * @param mixed $filter 参数过滤方法 * @return mixed */ function I($name, $filter = 'int', $default = null) { if (strpos($name, '.')) { // 指定参数来源 list($method, $name) = explode('.', $name, 2); } else { // 默认为post $method = 'post'; } switch (strtolower($method)) { case 'get': $input = $_GET; break; case 'post': $input = $_POST; break; case 'put': parse_str(file_get_contents('php://input'), $input); break; case 'request': $input = $_REQUEST; break; case 'session': $input = $_SESSION; break; case 'cookie': $input = $_COOKIE; break; case 'server': $input = $_SERVER; break; case 'globals': $input = $GLOBALS; break; default: return NULL; } $value = isset($input[$name]) ? $input[$name] : null; if (is_array($filter)) { return in_array($value, $filter) ? $value : $default; } if (!is_string($filter)) { return $value; } switch ($filter) { case 'int': return is_null($value) ? is_null($default) ? 0 : $default : intval($value); case 'str': return is_null($value) ? is_null($default) ? '' : $default : strval($value); case 'arr': return is_array($value) ? $value : (is_array($default) ? $default : array()); default: return empty($value) ? $default : (regex($value, $filter) ? $value : $default); } }
/** * * @test */ public function itShouldTestPattern() { $result = regex("/test/")->test(" this is a test"); $this->expectsThat($result)->isTrue(); }
<?php $tekst1 = "ggjkjkljhhkabc1w3e"; $tekst2 = "hgsjehdcfhjabciuoyiw4"; $reg1 = '*.abc[^1]*'; function regex($reg, $tekst) { if (preg_match($reg, $tekst, $matches)) { return true; } else { return false; } } if (regex($reg1, $tekst2)) { echo "Ciag znaleziony"; } else { echo "Ciag nie odnaleziony"; }
public function handleThreeAction() { Yaf_Dispatcher::getInstance()->disableView(); $openid = parent::getPost("openid"); $token = parent::getPost("token"); $type = parent::getPost("type"); $username = parent::getPost("username"); if (!regex($username, "require")) { die(json_encode(array("status" => 0, "msg" => "昵称不能为空"))); } $email = parent::getPost("email"); if (!regex($email, "require")) { die(json_encode(array("status" => 0, "msg" => "邮箱不能为空"))); } if (!regex($email, "email")) { die(json_encode(array("status" => 0, "msg" => "邮箱格式不正确"))); } $exist_email = $this->m_user->Where("email='" . $email . "'")->Field("id")->SelectOne(); if ($exist_email) { die(json_encode(array("status" => 0, "msg" => "邮箱已经注册过,请直接登录,如果忘记密码,请点击找回密码"))); } $exist_username = $this->m_user->Where("username='******'")->Field("id")->SelectOne(); if ($exist_username) { die(json_encode(array("status" => 0, "msg" => "昵称已经存在,请换一个"))); } $result = $this->m_user->Insert(array("email" => $email, "avatar" => "/img/face.jpg", "brief" => "这家伙有点懒,还没有写个性签名! ", "username" => $username, "reg_time" => time(), "login_time" => time(), "login_ip" => getClientIP(), "reg_type" => 2)); if ($result) { $model_user_three = $this->load('user_three'); $model_user_three->Insert(array("user_id" => $result, "openid" => $openid, "type" => $type)); //写入session parent::setSession('uid', $result); parent::setSession('email', $email); die(json_encode(array("status" => 1, "msg" => "绑定QQ成功。"))); } else { die(json_encode(array("status" => 0, "msg" => "绑定QQ失败,请稍后再试..."))); } }