本文整理汇总了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));
}
示例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'));
}
示例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 '';
});
}
示例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);
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例12: __construct
/**
* @param string $expr
*/
public function __construct($expr)
{
try {
$this->value = Regex::create($expr);
} catch (\InvalidArgumentException $e) {
$this->value = new Glob($expr);
}
}
示例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;
}
示例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;
}
示例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);
}