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


PHP Regex類代碼示例

本文整理匯總了PHP中Regex的典型用法代碼示例。如果您正苦於以下問題:PHP Regex類的具體用法?PHP Regex怎麽用?PHP Regex使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Regex類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testIsValidFor

 /**
  * @dataProvider isValidForProvider
  * @param string $pattern
  * @param string $name
  * @param bool $expectedResult
  */
 public function testIsValidFor($pattern, $name, $expectedResult)
 {
     $this->regex->setEventRegex($pattern);
     $eventMock = $this->getMock('Magento\\Framework\\Event', [], [], '', false);
     $eventMock->expects($this->any())->method('getName')->will($this->returnValue($name));
     $this->assertEquals($expectedResult, $this->regex->isValidFor($eventMock));
 }
開發者ID:,項目名稱:,代碼行數:13,代碼來源:

示例2: testValidMatchParamaters

 /**
  * Test a match where we can get the parameters (from the regex)
  */
 public function testValidMatchParamaters()
 {
     $config = array('route' => '/foo/bar/:id');
     $regex = new Regex($config);
     $this->assertTrue($regex->evaluate('/foo/bar/baz'));
     $params = $regex->getParams();
     $this->assertEquals($params, array('id' => 'baz'));
 }
開發者ID:psecio,項目名稱:invoke,代碼行數:11,代碼來源:RegexTest.php

示例3: svg_capture

function svg_capture($process)
{
    $process->string->pregReplaceCallback(Regex::make('~@svg\\s+(?<name>{{ ident }})\\s*{{ block }}~iS'), function ($m) {
        Crush::$process->misc->svg_defs[strtolower($m['name'])] = new Template($m['block_content']);
        return '';
    });
}
開發者ID:MrHidalgo,項目名稱:css-crush,代碼行數:7,代碼來源:svg.php

示例4: ajaxSendEmailAction

 public function ajaxSendEmailAction()
 {
     $email = Request::getPOST('email');
     $verify = Request::getPOST('verify');
     if (empty($verify)) {
         $this->renderAjax(1, '請輸入圖片驗證碼!');
     }
     if (empty($email)) {
         $this->renderAjax(1, '請填寫郵箱!');
     }
     // 校驗驗證碼
     $imgCode = Session::get('check_code');
     if (strtolower($verify) != $imgCode) {
         $this->renderAjax(2, '圖片驗證碼錯誤!');
     }
     if (!Regex::match($email, RegexVars::EMAIL)) {
         $this->renderAjax(1, '郵箱格式錯誤!');
     }
     // 是否存在
     $userInfo = UcUserInterface::getByLoginName(array('login_name' => $email));
     if (empty($userInfo)) {
         $this->renderAjax(1, '用戶郵箱不存在!');
     }
     $code = UcAuthInterface::sendEmailCode(array('email' => $email, 'repeat_at' => time() + 60));
     if (false === $code) {
         $this->renderAjax(1, '服務器繁忙,請1分鍾後重試!');
     }
     $this->renderAjax(0);
 }
開發者ID:aozhongxu,項目名稱:web_hqoj,代碼行數:29,代碼來源:FindController.class.php

示例5: __invoke

 public function __invoke($args)
 {
     $handler = $this->handler;
     $tokens = Crush::$process->tokens;
     $splat_arg_patt = Regex::make('~#\\((?<fallback>{{ ident }})?\\)~');
     switch ($this->type) {
         case 'alias':
             return $handler($args);
         case 'callback':
             $template = new Template($handler($args));
             return $template($args);
         case 'splat':
             $handler = $tokens->restore($handler, 's');
             if ($args) {
                 $list = array();
                 foreach ($args as $arg) {
                     $list[] = SelectorAlias::wrap($tokens->capture(preg_replace($splat_arg_patt, $arg, $handler), 's'));
                 }
                 $handler = implode(',', $list);
             } else {
                 $handler = $tokens->capture(preg_replace_callback($splat_arg_patt, function ($m) {
                     return $m['fallback'];
                 }, $handler), 's');
             }
             return SelectorAlias::wrap($handler);
     }
 }
開發者ID:MrHidalgo,項目名稱:css-crush,代碼行數:27,代碼來源:SelectorAlias.php

示例6: internalRouteURI

function internalRouteURI(string $requestUri = '') : string
{
    $config = Config::get('Services', 'route');
    if ($config['openPage']) {
        $internalDir = NULL;
        if (defined('_CURRENT_PROJECT')) {
            $configAppdir = PROJECTS_CONFIG['directory']['others'];
            if (is_array($configAppdir)) {
                $internalDir = !empty($configAppdir[$requestUri]) ? $requestUri : _CURRENT_PROJECT;
            } else {
                $internalDir = _CURRENT_PROJECT;
            }
        }
        if ($requestUri === DIRECTORY_INDEX || $requestUri === getLang() || $requestUri === $internalDir || empty($requestUri)) {
            $requestUri = $config['openPage'];
        }
    }
    $uriChange = $config['changeUri'];
    $patternType = $config['patternType'];
    if (!empty($uriChange)) {
        foreach ($uriChange as $key => $val) {
            if ($patternType === 'classic') {
                $requestUri = preg_replace(presuffix($key) . 'xi', $val, $requestUri);
            } else {
                $requestUri = Regex::replace($key, $val, $requestUri, 'xi');
            }
        }
    }
    return $requestUri;
}
開發者ID:znframework,項目名稱:znframework,代碼行數:30,代碼來源:Internal.php

示例7: loop_resolve_list

function loop_resolve_list($list_text)
{
    // Resolve the list of items for iteration.
    // Either a generator function or a plain list.
    $items = array();
    $list_text = Crush::$process->functions->apply($list_text);
    $generator_func_patt = Regex::make('~(?<func>range|color-range) {{parens}}~ix');
    if (preg_match($generator_func_patt, $list_text, $m)) {
        $func = strtolower($m['func']);
        $args = Functions::parseArgs($m['parens_content']);
        switch ($func) {
            case 'range':
                $items = call_user_func_array('range', $args);
                break;
            default:
                $func = str_replace('-', '_', $func);
                if (function_exists("CssCrush\\loop_{$func}")) {
                    $items = call_user_func_array("CssCrush\\loop_{$func}", $args);
                }
        }
    } else {
        $items = Util::splitDelimList($list_text);
    }
    return $items;
}
開發者ID:MrHidalgo,項目名稱:css-crush,代碼行數:25,代碼來源:loop.php

示例8: ajaxSubmitAction

 public function ajaxSubmitAction()
 {
     $username = Request::getPOST('username');
     $password = Request::getPOST('password');
     $verify = Request::getPOST('verify');
     if (!Regex::match($username, RegexVars::USERNAME)) {
         $this->renderAjax(1, '用戶名格式不正確!');
     }
     // 校驗密碼格式
     if (!Regex::match($password, RegexVars::PASSWORD)) {
         $this->renderAjax(1, '密碼長度為6-20位!');
     }
     // 校驗驗證碼
     $code = Session::get('check_code');
     if (strtolower($verify) != $code) {
         $this->renderAjax(1, '驗證碼錯誤,請重試!');
     }
     // 過濾用戶名
     if (false !== strpos(strtolower($username), 'admin')) {
         $this->renderAjax(1, '用戶已經存在!');
     }
     // 校驗用戶是否存在
     $userInfo = UcUserInterface::getByLoginName(array('login_name' => $username));
     if (!empty($userInfo)) {
         $this->renderAjax(1, '用戶名已經被占用!');
     }
     // 保存
     $data = array('username' => $username, 'password' => $password, 'reg_ip' => Http::getClientIp());
     UcUserInterface::save($data);
     $this->renderAjax(0);
 }
開發者ID:aozhongxu,項目名稱:web_hqoj,代碼行數:31,代碼來源:RegisterController.class.php

示例9: ncEncode

 public function ncEncode($string = '', $badWords = '', $changeChar = '[badchars]')
 {
     if (!is_string($string)) {
         return Error::set(lang('Error', 'stringParameter', 'string'));
     }
     // 2. Parametre boş ise varsayılan olarak Config/Security.php dosya ayarlarını kullan.
     if (empty($badWords)) {
         $secnc = $this->config['ncEncode'];
         $badWords = $secnc['bad_chars'];
         $changeChar = $secnc['change_bad_chars'];
     }
     if (!is_array($badWords)) {
         return $string = Regex::replace($badWords, $changeChar, $string, 'xi');
     }
     $ch = '';
     $i = 0;
     foreach ($badWords as $value) {
         if (!is_array($changeChar)) {
             $ch = $changeChar;
         } else {
             if (isset($changeChar[$i])) {
                 $ch = $changeChar[$i];
                 $i++;
             }
         }
         $string = Regex::replace($value, $ch, $string, 'xi');
     }
     return $string;
 }
開發者ID:Allopa,項目名稱:ZN-Framework-Starter,代碼行數:29,代碼來源:Security.php

示例10: word

 public function word($string = '', $badWords = '', $changeChar = '[badwords]')
 {
     if (!isValue($string)) {
         return Error::set(lang('Error', 'valueParameter', 'string'));
     }
     if (!is_array($badWords)) {
         if (empty($badWords)) {
             return $string;
         }
         return $string = Regex::replace($badWords, $changeChar, $string, 'xi');
     }
     $ch = '';
     $i = 0;
     if (!empty($badWords)) {
         foreach ($badWords as $value) {
             if (!is_array($changeChar)) {
                 $ch = $changeChar;
             } else {
                 if (isset($changeChar[$i])) {
                     $ch = $changeChar[$i];
                     $i++;
                 }
             }
             $string = Regex::replace($value, $ch, $string, 'xi');
         }
     }
     return $string;
 }
開發者ID:Allopa,項目名稱:ZN-Framework-Starter,代碼行數:28,代碼來源:Filter.php

示例11: process

 public static function process($directory = "", $defaults, $config = array())
 {
     PipelineHooks::beforeProcessingFilesIn($directory, $defaults, $config);
     // Hook for before this directory is processed
     $configPath = $directory . "config.json";
     if (file_exists($configPath)) {
         CL::printDebug("Config File at: " . $configPath, 1);
     }
     $config = Secretary::getJSON($configPath, $config);
     if (array_key_exists("Content", $config)) {
         CL::println("WARNING: You've declared field \"Content\" in JSON file: " . $directory . "config.json", 0, Colour::Red);
         CL::println("The \"Content\" keyword is reserved for storing the file contents in.", 0, Colour::Red);
         CL::println("The value for \"Content\" stored in the JSON file will be ignored.", 0, Colour::Red);
     }
     $files = array();
     $markdowns = glob($directory . "*.md");
     foreach ($markdowns as $markdown) {
         CL::printDebug("Processing: " . $markdown);
         $file = new File($markdown);
         // Set up our @data
         $data = array_merge($config, $file->data);
         // Renaming to make more semantic sense as we're now working with the "data"
         $data["Content"] = $file->contents;
         // Pass in our file contents
         $raw = $data;
         // Store raw data before processing
         // Process our data through data extensions
         if (array_key_exists("DataExtensions", $defaults)) {
             $data = DataProcessor::process($data, $defaults["DataExtensions"]);
             // Process our data to be filled in
             CL::printDebug("Processed data", 1, Colour::Green);
         } else {
             CL::printDebug("No data extensions declared", 1);
         }
         $data["Content"] = Regex::process($data["Content"]);
         // Now regex it all
         CL::printDebug("Processed Regex", 1, Colour::Green);
         $templateFile = Templater::process($data["Template"]);
         // Generate our template
         CL::printDebug("Processed template: " . $data["Template"], 1, Colour::Green);
         $processedFile = LTM::process($templateFile, $data, $raw);
         // Fill in any conditions and optionals
         CL::printDebug("Processed LTM", 1, Colour::Green);
         $file->contents = $processedFile;
         // Store the complete processed file back into the file object
         array_push($files, $file);
         // Add it to the array ready to be exported!
     }
     PipelineHooks::afterProcessing($files, $directory, $defaults, $config);
     // Hook for after this directory is processed - and lets pass some files!
     $directories = glob($directory . "*", GLOB_ONLYDIR);
     foreach ($directories as $directory) {
         $newFiles = self::process($directory . "/", $defaults, $config);
         foreach ($newFiles as $newFile) {
             array_push($files, $newFile);
         }
     }
     return $files;
 }
開發者ID:OhItsShaun,項目名稱:Warehouse,代碼行數:59,代碼來源:class.FilesProcessor.php

示例12: __construct

 /**
  * @param string $expr
  */
 public function __construct($expr)
 {
     try {
         $this->value = Regex::create($expr);
     } catch (\InvalidArgumentException $e) {
         $this->value = new Glob($expr);
     }
 }
開發者ID:BozzaCoon,項目名稱:SPHERE-Framework,代碼行數:11,代碼來源:Expression.php

示例13: getController

 private static function getController($location)
 {
     $location = strtolower($location);
     $pattern = '/controller/';
     $match = Regex::match($pattern, $location);
     if ($match > 0) {
         $location = Regex::replace($pattern, '', $location);
     }
     return $location;
 }
開發者ID:anzasolutions,項目名稱:simlandia,代碼行數:10,代碼來源:navigator.class.php

示例14: expand

 public function expand()
 {
     static $grouping_patt, $expand, $expandSelector;
     if (!$grouping_patt) {
         $grouping_patt = Regex::make('~\\:any{{ parens }}~iS');
         $expand = function ($selector_string) use($grouping_patt) {
             if (preg_match($grouping_patt, $selector_string, $m, PREG_OFFSET_CAPTURE)) {
                 list($full_match, $full_match_offset) = $m[0];
                 $before = substr($selector_string, 0, $full_match_offset);
                 $after = substr($selector_string, strlen($full_match) + $full_match_offset);
                 $selectors = array();
                 // Allowing empty strings for more expansion possibilities.
                 foreach (Util::splitDelimList($m['parens_content'][0], array('allow_empty_strings' => true)) as $segment) {
                     if ($selector = trim("{$before}{$segment}{$after}")) {
                         $selectors[$selector] = true;
                     }
                 }
                 return $selectors;
             }
             return false;
         };
         $expandSelector = function ($selector_string) use($expand) {
             if ($running_stack = $expand($selector_string)) {
                 $flattened_stack = array();
                 do {
                     $loop_stack = array();
                     foreach ($running_stack as $selector => $bool) {
                         $selectors = $expand($selector);
                         if (!$selectors) {
                             $flattened_stack += array($selector => true);
                         } else {
                             $loop_stack += $selectors;
                         }
                     }
                     $running_stack = $loop_stack;
                 } while ($loop_stack);
                 return $flattened_stack;
             }
             return array($selector_string => true);
         };
     }
     $expanded_set = array();
     foreach ($this->store as $original_selector) {
         if (stripos($original_selector->value, ':any(') !== false) {
             foreach ($expandSelector($original_selector->value) as $selector_string => $bool) {
                 $new = new Selector($selector_string);
                 $expanded_set[$new->readableValue] = $new;
             }
         } else {
             $expanded_set[$original_selector->readableValue] = $original_selector;
         }
     }
     $this->store = $expanded_set;
 }
開發者ID:MrHidalgo,項目名稱:css-crush,代碼行數:54,代碼來源:SelectorList.php

示例15: find

 /**
  * @Invocable
  */
 protected function find()
 {
     if ($this->request->hasKey('friend')) {
         $name = Regex::replace('/[^A-Za-z0-9]/', '', $this->request->valueOf('friend'));
         Navigator::redirectTo($this->url->getParametersPath($name));
     }
     $name = $this->url->getParameter(0);
     if ($name == null) {
         return;
     }
     $this->getUsers($name);
 }
開發者ID:anzasolutions,項目名稱:simlandia,代碼行數:15,代碼來源:friendscontroller.class.php


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