本文整理汇总了PHP中Regex类的典型用法代码示例。如果您正苦于以下问题:PHP Regex类的具体用法?PHP Regex怎么用?PHP Regex使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Regex类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: hsl2hex
function hsl2hex(Rule $rule)
{
$hsl_patt = Regex::make('~{{ LB }}hsl({{ parens }})~i');
foreach ($rule->declarations->filter(array('skip' => false)) as $declaration) {
if (isset($declaration->functions['hsl'])) {
$declaration->value = preg_replace_callback($hsl_patt, function ($m) {
$color = new Color($m[0]);
return $color->getHex();
}, $declaration->value);
}
}
}
开发者ID:MrHidalgo,项目名称:css-crush,代码行数:12,代码来源:hsl2hex.php
示例17: ajaxUpdatePasswordAction
public function ajaxUpdatePasswordAction()
{
// 获取参数
$oldPassword = Request::getPOST('old-password');
$password = trim(Request::getPOST('password'));
if (!Regex::match($password, RegexVars::PASSWORD)) {
$this->renderError('新密码限制为6-20位!');
}
$encryptPassword = UserCommonInterface::encryptPassword(array('password' => $oldPassword));
if ($encryptPassword != $this->loginUserInfo['password']) {
$this->renderError('旧密码不正确!');
}
$data = array('id' => $this->loginUserInfo['id'], 'password' => $password);
UserCommonInterface::save($data);
UserCommonInterface::logout();
$this->renderAjax(0);
}
开发者ID:aozhongxu,项目名称:web_hqoj,代码行数:17,代码来源:PasswordController.class.php
示例18: postalias_fix_radial_gradients
/**
* Remove the 'at' keyword from -x-radial-gradient() for legacy implementations.
*/
function postalias_fix_radial_gradients($declaration_copies)
{
// Create new paren tokens based on the first prefixed declaration.
// Replace the new syntax with the legacy syntax.
static $fn_patt;
if (!$fn_patt) {
$fn_patt = Regex::make('~{{ LB }}{{ vendor }}(?:repeating-)?radial-gradient{{ parens }}~iS');
}
$original_parens = array();
$replacement_parens = array();
foreach (Regex::matchAll($fn_patt, $declaration_copies[0]->value) as $m) {
$original_parens[] = $m['parens'][0];
$replacement_parens[] = preg_replace('~\\bat +(top|left|bottom|right|center)\\b~i', '$1', $m['parens'][0]);
}
foreach ($declaration_copies as $prefixed_copy) {
$prefixed_copy->value = str_replace($original_parens, $replacement_parens, $prefixed_copy->value);
}
}
开发者ID:MrHidalgo,项目名称:css-crush,代码行数:21,代码来源:PostAliasFix.php
示例19: color_capture
function color_capture($process)
{
$captured_keywords = $process->string->captureDirectives('color', array('singles' => true));
if ($captured_keywords) {
$native_keywords = Color::getKeywords();
$custom_keywords = array();
$process->colorKeywords = $native_keywords;
foreach ($captured_keywords as $key => $value) {
$value = $process->functions->apply($value);
if (!isset($native_keywords[$key]) && ($rgba = Color::parse($value))) {
$custom_keywords[] = $key;
$process->stat['colors'][$key] = new Color($rgba);
$process->colorKeywords[$key] = $rgba;
}
}
if ($custom_keywords) {
$GLOBALS['CSSCRUSH_COLOR_PATT'] = Regex::make('~{{ LB }}(?<color_keyword>' . implode('|', $custom_keywords) . '){{ RB }}~iS');
}
}
}
开发者ID:MrHidalgo,项目名称:css-crush,代码行数:20,代码来源:color.php
示例20: ajaxSendEmailAction
public function ajaxSendEmailAction()
{
$email = Request::getPOST('email');
if (empty($email)) {
$this->renderError('请填写邮箱!');
}
if (!Regex::match($email, RegexVars::EMAIL)) {
$this->renderError('邮箱格式错误!');
}
// 是否已经被绑定
$userInfo = UserCommonInterface::getByLoginName(array('login_name' => $email));
if (!empty($userInfo)) {
$this->renderError('该邮箱已经被绑定!');
}
$code = AuthCommonInterface::sendEmailCode(array('email' => $email, 'repeat_at' => time() + 60));
if (false === $code) {
$this->renderError('服务器繁忙,请1分钟后重试!');
}
$this->renderAjax(0);
}
开发者ID:aozhongxu,项目名称:web_hqoj,代码行数:20,代码来源:EmailController.class.php
注:本文中的Regex类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论