當前位置: 首頁>>代碼示例>>PHP>>正文


PHP regex函數代碼示例

本文整理匯總了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);
     }
 }
開發者ID:GobYang,項目名稱:zhizhao,代碼行數:28,代碼來源:CommonAction.class.php

示例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);
}
開發者ID:a53ali,項目名稱:CakePhP,代碼行數:8,代碼來源:analyze.php

示例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();
 }
開發者ID:vulcan-project,項目名稱:rivescript-php,代碼行數:10,代碼來源:Bot.php

示例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;
     }
 }
開發者ID:GobYang,項目名稱:thaidh,代碼行數:47,代碼來源:Member.php

示例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;
}
開發者ID:n2bh,項目名稱:PHP-Parser,代碼行數:13,代碼來源:rebuildParsers.php

示例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);
    }
}
開發者ID:amlun,項目名稱:spidermonkey,代碼行數:34,代碼來源:zillow.php

示例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);
 }
開發者ID:amptools-net,項目名稱:midori-php,代碼行數:12,代碼來源:String.php

示例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);
    }
}
開發者ID:oohook,項目名稱:PTFrameWork,代碼行數:63,代碼來源:ptcms.php

示例9: itShouldTestPattern

 /**
  *
  * @test
  */
 public function itShouldTestPattern()
 {
     $result = regex("/test/")->test(" this is a test");
     $this->expectsThat($result)->isTrue();
 }
開發者ID:amptools-net,項目名稱:midori-php,代碼行數:9,代碼來源:RegexSpec.php

示例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";
}
開發者ID:sparrow41,項目名稱:training,代碼行數:18,代碼來源:regex.php

示例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失敗,請稍後再試...")));
     }
 }
開發者ID:GobYang,項目名稱:thaidh,代碼行數:37,代碼來源:Login.php


注:本文中的regex函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。