本文整理汇总了PHP中regex函数的典型用法代码示例。如果您正苦于以下问题:PHP regex函数的具体用法?PHP regex怎么用?PHP regex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了regex函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkField
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);
}
}
示例2: magicSplit
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);
}
示例3: __construct
/**
* Create a new Bot instance.
*
* @param array $tree
*/
public function __construct($tree)
{
$this->tree = $tree;
$this->pattern = regex()->find('<bot ')->anythingBut('>')->asGroup()->then('>')->getRegExp();
}
示例4: handlePasswdAction
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;
}
}
示例5: magicSplit
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;
}
示例6: parse_property
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);
}
}
示例7: match
/**
*
* 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);
}
示例8: I
/**
* 获取输入参数 支持过滤和默认值
*
* @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);
}
}
示例9: itShouldTestPattern
/**
*
* @test
*/
public function itShouldTestPattern()
{
$result = regex("/test/")->test(" this is a test");
$this->expectsThat($result)->isTrue();
}
示例10: regex
<?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";
}
示例11: handleThreeAction
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='" . $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失败,请稍后再试...")));
}
}