本文整理汇总了PHP中Regex::matchAll方法的典型用法代码示例。如果您正苦于以下问题:PHP Regex::matchAll方法的具体用法?PHP Regex::matchAll怎么用?PHP Regex::matchAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Regex
的用法示例。
在下文中一共展示了Regex::matchAll方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
}
示例2: apply
public function apply($str, \stdClass $context = null)
{
if (strpos($str, '(') === false) {
return $str;
}
if (!$this->pattern) {
$this->setPattern();
}
if (!preg_match($this->pattern, $str)) {
return $str;
}
$matches = Regex::matchAll($this->pattern, $str);
while ($match = array_pop($matches)) {
if (isset($match['function']) && $match['function'][1] !== -1) {
list($function, $offset) = $match['function'];
} else {
list($function, $offset) = $match['simple_function'];
}
if (!preg_match(Regex::$patt->parens, $str, $parens, PREG_OFFSET_CAPTURE, $offset)) {
continue;
}
$openingParen = $parens[0][1];
$closingParen = $openingParen + strlen($parens[0][0]);
$rawArgs = trim($parens['parens_content'][0]);
// Update the context function identifier.
if ($context) {
$context->function = $function;
}
$returns = '';
if (isset($this->register[$function])) {
$fn = $this->register[$function];
if (is_array($fn) && !empty($fn['parse_args'])) {
$returns = $fn['callback'](self::parseArgs($rawArgs), $context);
} else {
$returns = $fn($rawArgs, $context);
}
}
$str = substr_replace($str, $returns, $offset, $closingParen - $offset);
}
return $str;
}
示例3: resolveInBlocks
protected function resolveInBlocks()
{
$matches = $this->string->matchAll('~@in\\s+(?<selectors>[^{]+)\\{~iS');
while ($match = array_pop($matches)) {
$selectorsMatch = trim($match['selectors'][0]);
$curlyMatch = new BalancedMatch($this->string, $match[0][1]);
if (!$curlyMatch->match || empty($selectorsMatch)) {
continue;
}
$rawSelectors = Util::splitDelimList($selectorsMatch);
foreach (Regex::matchAll(Regex::$patt->r_token, $curlyMatch->inside()) as $ruleMatch) {
Crush::$process->tokens->get($ruleMatch[0][0])->selectors->merge($rawSelectors);
}
$curlyMatch->unWrap();
}
}
示例4: collate
public function collate()
{
$process = $this->process;
$options = $process->options;
$regex = Regex::$patt;
$input = $process->input;
$str = '';
// Keep track of all import file info for cache data.
$mtimes = array();
$filenames = array();
// Resolve main input; a string of css or a file.
if (isset($input->string)) {
$str .= $input->string;
$process->sources[] = 'Inline CSS';
} else {
$str .= file_get_contents($input->path);
$process->sources[] = $input->path;
}
// If there's a parsing error go no further.
if (!$this->prepareImport($str)) {
return $str;
}
// This may be set non-zero during the script if an absolute @import URL is encountered.
$search_offset = 0;
// Recurses until the nesting heirarchy is flattened and all import files are inlined.
while (preg_match($regex->import, $str, $match, PREG_OFFSET_CAPTURE, $search_offset)) {
$match_len = strlen($match[0][0]);
$match_start = $match[0][1];
$import = new \stdClass();
$import->url = $process->tokens->get($match[1][0]);
$import->media = trim($match[2][0]);
// Protocoled import urls are not processed. Stash for prepending to output.
if ($import->url->protocol) {
$str = substr_replace($str, '', $match_start, $match_len);
$process->absoluteImports[] = $import;
continue;
}
// Resolve import path information.
if ($import->url->isRooted) {
$import->path = realpath($process->docRoot . $import->url->value);
} else {
$import->path = realpath("{$input->dir}/{$import->url->value}");
}
$import->dir = dirname($import->path);
// If unsuccessful getting import contents continue with the import line removed.
$import->content = @file_get_contents($import->path);
if ($import->content === false) {
notice("Import file '{$import->url->value}' not found");
$str = substr_replace($str, '', $match_start, $match_len);
continue;
}
// Import file exists so register it.
$process->sources[] = $import->path;
$mtimes[] = filemtime($import->path);
$filenames[] = $import->url->value;
// If the import content doesn't pass syntax validation skip to next import.
if (!$this->prepareImport($import->content)) {
$str = substr_replace($str, '', $match_start, $match_len);
continue;
}
// Resolve a relative link between the import file and the host-file.
if ($import->url->isRooted) {
$import->relativeDir = Util::getLinkBetweenPaths($import->dir, $input->dir);
} else {
$import->relativeDir = dirname($import->url->value);
}
// Alter all embedded import URLs to be relative to the host-file.
foreach (Regex::matchAll($regex->import, $import->content) as $m) {
$nested_url = $process->tokens->get($m[1][0]);
// Resolve rooted paths.
if ($nested_url->isRooted) {
$link = Util::getLinkBetweenPaths(dirname($nested_url->getAbsolutePath()), $import->dir);
$nested_url->update($link . basename($nested_url->value));
} elseif (strlen($import->relativeDir)) {
$nested_url->prepend("{$import->relativeDir}/");
}
}
// Optionally rewrite relative url and custom function data-uri references.
if ($options->rewrite_import_urls) {
$this->rewriteImportedUrls($import);
}
if ($import->media) {
$import->content = "@media {$import->media} {{$import->content}}";
}
$str = substr_replace($str, $import->content, $match_start, $match_len);
}
// Save only if caching is on and the hostfile object is associated with a real file.
if ($input->path && $options->cache) {
$process->cacheData[$process->output->filename] = array('imports' => $filenames, 'datem_sum' => array_sum($mtimes) + $input->mtime, 'options' => $options->get());
$process->io->saveCacheData();
}
return $str;
}
示例5: matchAll
public function matchAll($patt, $offset = 0)
{
return Regex::matchAll($patt, $this->raw, $offset);
}