当前位置: 首页>>代码示例>>PHP>>正文


PHP Strings::matchAll方法代码示例

本文整理汇总了PHP中Nette\Utils\Strings::matchAll方法的典型用法代码示例。如果您正苦于以下问题:PHP Strings::matchAll方法的具体用法?PHP Strings::matchAll怎么用?PHP Strings::matchAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Nette\Utils\Strings的用法示例。


在下文中一共展示了Strings::matchAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: el

 /**
  * Static factory.
  * @param  string element name (or NULL)
  * @param  array|string element's attributes or plain text content
  * @return self
  */
 public static function el($name = NULL, $attrs = NULL)
 {
     $el = new static();
     $parts = explode(' ', $name, 2);
     $el->setName($parts[0]);
     if (is_array($attrs)) {
         $el->attrs = $attrs;
     } elseif ($attrs !== NULL) {
         $el->setText($attrs);
     }
     if (isset($parts[1])) {
         foreach (Strings::matchAll($parts[1] . ' ', '#([a-z0-9:-]+)(?:=(["\'])?(.*?)(?(2)\\2|\\s))?#i') as $m) {
             $el->attrs[$m[1]] = isset($m[3]) ? $m[3] : TRUE;
         }
     }
     return $el;
 }
开发者ID:chriss-inno,项目名称:misscontest,代码行数:23,代码来源:Html.php

示例2: parseQuery

 /**
  * Parse search query.
  *
  * @param  string
  * @return array associative array with keys 'query' and 'tags'
  */
 public function parseQuery($input)
 {
     // normalize input
     $input = Strings::lower(Strings::trim($input));
     $input = Strings::replace($input, '/\\s+/', ' ');
     // extract tags
     $matches = Strings::matchAll($input, '/(?<=^|\\s)tag:\\s*(?<tag_list>[\\pL\\d_-]+(?:\\s*,\\s*(?&tag_list))?)/u');
     $tags = array();
     $query = $input;
     foreach ($matches as $m) {
         $tmp = Strings::split($m['tag_list'], '/\\s*,\\s*/');
         $tmp = array_map('Nette\\Utils\\Strings::webalize', $tmp);
         $tmp = array_unique($tmp);
         $tags = array_merge($tags, $tmp);
         $query = str_replace($m[0], '', $query);
     }
     $query = Strings::trim($query) ?: null;
     return array('query' => $query, 'tags' => $tags);
 }
开发者ID:zoidbergthepopularone,项目名称:fitak,代码行数:25,代码来源:SearchQueryParser.php

示例3: proccessTweetForm

 public function proccessTweetForm($form, array $values)
 {
     $text = $values['tweet'];
     $matches = Strings::matchAll($text, '~#([a-z0-9-]++)~');
     $tags = array_column($matches, 1);
     $user = $this->users->getById($this->userId);
     $tweet = new Model\Tweet();
     $tweet->user = $user;
     $tweet->text = $values['tweet'];
     $existingTags = $this->tags->findBy(['name' => $tags])->fetchPairs('name');
     $newTags = array_diff($tags, array_keys($existingTags));
     foreach ($newTags as $tag) {
         $tweet->tags->add(new Model\Tag($tag));
     }
     foreach ($existingTags as $tag) {
         $tweet->tags->add($tag);
     }
     $this->tweets->persist($tweet);
     $this->tweets->flush();
     $this->redirect('this');
 }
开发者ID:NetteCamp,项目名称:2015-nextras-orm-twitter,代码行数:21,代码来源:TweetPresenter.php

示例4: tokenize

 /**
  * Tokenize string.
  * @param  string
  * @return array
  */
 public function tokenize($input)
 {
     $this->input = $input;
     if ($this->types) {
         $this->tokens = Strings::matchAll($input, $this->re);
         $len = 0;
         $count = count($this->types);
         $line = 1;
         foreach ($this->tokens as &$match) {
             $type = NULL;
             for ($i = 1; $i <= $count; $i++) {
                 if (!isset($match[$i])) {
                     break;
                 } elseif ($match[$i] != NULL) {
                     $type = $this->types[$i - 1];
                     break;
                 }
             }
             $match = self::createToken($match[0], $type, $line);
             $len += strlen($match['value']);
             $line += substr_count($match['value'], "\n");
         }
         if ($len !== strlen($input)) {
             $errorOffset = $len;
         }
     } else {
         $this->tokens = Strings::split($input, $this->re, PREG_SPLIT_NO_EMPTY);
         if ($this->tokens && !Strings::match(end($this->tokens), $this->re)) {
             $tmp = Strings::split($this->input, $this->re, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE);
             list(, $errorOffset) = end($tmp);
         }
     }
     if (isset($errorOffset)) {
         $line = $errorOffset ? substr_count($this->input, "\n", 0, $errorOffset) + 1 : 1;
         $col = $errorOffset - strrpos(substr($this->input, 0, $errorOffset), "\n") + 1;
         $token = str_replace("\n", '\\n', substr($input, $errorOffset, 10));
         throw new TokenizerException("Unexpected '{$token}' on line {$line}, column {$col}.");
     }
     return $this->tokens;
 }
开发者ID:exesek,项目名称:nette20login,代码行数:45,代码来源:Tokenizer.php

示例5: setHtmlBody

 /**
  * Sets HTML body.
  * @param  string
  * @param  mixed base-path or FALSE to disable parsing
  * @return MandrillMessage  provides a fluent interface
  */
 public function setHtmlBody($html, $basePath = NULL)
 {
     if ($html instanceof ITemplate) {
         //$html->mail = $this;
         if ($basePath === NULL && $html instanceof IFileTemplate) {
             $basePath = dirname($html->getFile());
         }
         $html = $html->__toString(TRUE);
     }
     if ($basePath !== FALSE) {
         $cids = array();
         $matches = Strings::matchAll($html, '#(src\\s*=\\s*|background\\s*=\\s*|url\\()(["\'])(?![a-z]+:|[/\\#])(.+?)\\2#i', PREG_OFFSET_CAPTURE);
         foreach (array_reverse($matches) as $m) {
             $file = rtrim($basePath, '/\\') . '/' . $m[3][0];
             if (!isset($cids[$file])) {
                 $cids[$file] = substr($this->addEmbeddedFile($file)->getHeader("Content-ID"), 1, -1);
             }
             $html = substr_replace($html, "{$m[1][0]}{$m[2][0]}cid:{$cids[$file]}{$m[2][0]}", $m[0][1], strlen($m[0][0]));
         }
     }
     $this->mandrillMessage['html'] = $html;
     return $this;
 }
开发者ID:nasext,项目名称:mandrill,代码行数:29,代码来源:MandrillMessage.php

示例6: tokenize

 /**
  * Tokenize string.
  * @param  string
  * @return array
  */
 public function tokenize($input)
 {
     if ($this->types) {
         $tokens = Strings::matchAll($input, $this->re);
         $len = 0;
         $count = count($this->types);
         foreach ($tokens as &$match) {
             $type = NULL;
             for ($i = 1; $i <= $count; $i++) {
                 if (!isset($match[$i])) {
                     break;
                 } elseif ($match[$i] != NULL) {
                     $type = $this->types[$i - 1];
                     break;
                 }
             }
             $match = array(self::VALUE => $match[0], self::OFFSET => $len, self::TYPE => $type);
             $len += strlen($match[self::VALUE]);
         }
         if ($len !== strlen($input)) {
             $errorOffset = $len;
         }
     } else {
         $tokens = Strings::split($input, $this->re, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE);
         $last = end($tokens);
         if ($tokens && !Strings::match($last[0], $this->re)) {
             $errorOffset = $last[1];
         }
     }
     if (isset($errorOffset)) {
         list($line, $col) = $this->getCoordinates($input, $errorOffset);
         $token = str_replace("\n", '\\n', substr($input, $errorOffset, 10));
         throw new TokenizerException("Unexpected '{$token}' on line {$line}, column {$col}.");
     }
     return $tokens;
 }
开发者ID:xamiro-dev,项目名称:xamiro,代码行数:41,代码来源:Tokenizer.php

示例7: analyseColumns

 /**
  * @param Table $table
  */
 protected function analyseColumns(Table $table)
 {
     $tableName = $table->getName();
     // Analyse columns
     $columns = $this->driver->getColumns($tableName);
     foreach ($columns as $key => $col) {
         $column = new Column();
         $column->setName($col['name']);
         $column->setNullable($col['nullable']);
         $column->setType(Helpers::columnType($col['nativetype']));
         $column->setDefault($col['default']);
         $column->setOnUpdate(Strings::contains($col['vendor']['Extra'], 'on update'));
         // Analyse ENUM
         if ($col['nativetype'] === ColumnTypes::NATIVE_TYPE_ENUM) {
             $enum = Strings::matchAll($col['vendor']['Type'], ColumnTypes::NATIVE_REGEX_ENUM, PREG_PATTERN_ORDER);
             if ($enum) {
                 $column->setEnum($enum[1]);
                 $column->setType(ColumnTypes::TYPE_ENUM);
                 $column->setSubType(Helpers::columnType($col['nativetype']));
             }
         }
         $table->addColumn($column);
     }
 }
开发者ID:minetro,项目名称:normgen,代码行数:27,代码来源:DatabaseAnalyser.php

示例8: setHtmlBody

 /**
  * Sets HTML body.
  * @param  string
  * @param  mixed base-path
  * @return self
  */
 public function setHtmlBody($html, $basePath = NULL)
 {
     if ($basePath === NULL && ($html instanceof Nette\Templating\IFileTemplate || $html instanceof Nette\Application\UI\ITemplate)) {
         $basePath = dirname($html->getFile());
         $bc = TRUE;
     }
     $html = (string) $html;
     if ($basePath) {
         $cids = array();
         $matches = Strings::matchAll($html, '#(src\\s*=\\s*|background\\s*=\\s*|url\\()(["\']?)(?![a-z]+:|[/\\#])([^"\')\\s]+)#i', PREG_OFFSET_CAPTURE);
         if ($matches && isset($bc)) {
             trigger_error(__METHOD__ . '() missing second argument with image base path.', E_USER_WARNING);
         }
         foreach (array_reverse($matches) as $m) {
             $file = rtrim($basePath, '/\\') . '/' . urldecode($m[3][0]);
             if (!isset($cids[$file])) {
                 $cids[$file] = substr($this->addEmbeddedFile($file)->getHeader('Content-ID'), 1, -1);
             }
             $html = substr_replace($html, "{$m[1][0]}{$m[2][0]}cid:{$cids[$file]}", $m[0][1], strlen($m[0][0]));
         }
     }
     if ($this->getSubject() == NULL) {
         // intentionally ==
         $html = Strings::replace($html, '#<title>(.+?)</title>#is', function ($m) use(&$title) {
             $title = $m[1];
         });
         $this->setSubject(html_entity_decode($title, ENT_QUOTES, 'UTF-8'));
     }
     $this->html = ltrim(str_replace("\r", '', $html), "\n");
     if ($this->getBody() == NULL && $html != NULL) {
         // intentionally ==
         $this->setBody($this->buildText($html));
     }
     return $this;
 }
开发者ID:norik16,项目名称:TripMap,代码行数:41,代码来源:Message.php

示例9: setHtmlBody

 /**
  * Sets HTML body.
  * @param  string|Nette\Templating\ITemplate
  * @param  mixed base-path or FALSE to disable parsing
  * @return self
  */
 public function setHtmlBody($html, $basePath = NULL)
 {
     if ($html instanceof Nette\Templating\ITemplate || $html instanceof Nette\Application\UI\ITemplate) {
         $html->mail = $this;
         if ($basePath === NULL && ($html instanceof Nette\Templating\IFileTemplate || $html instanceof Nette\Application\UI\ITemplate)) {
             $basePath = dirname($html->getFile());
         }
         $html = $html->__toString(TRUE);
     }
     if ($basePath !== FALSE) {
         $cids = array();
         $matches = Strings::matchAll($html, '#(src\\s*=\\s*|background\\s*=\\s*|url\\()(["\']?)(?![a-z]+:|[/\\#])([^"\')\\s]+)#i', PREG_OFFSET_CAPTURE);
         foreach (array_reverse($matches) as $m) {
             $file = rtrim($basePath, '/\\') . '/' . $m[3][0];
             if (!isset($cids[$file])) {
                 $cids[$file] = substr($this->addEmbeddedFile($file)->getHeader('Content-ID'), 1, -1);
             }
             $html = substr_replace($html, "{$m[1][0]}{$m[2][0]}cid:{$cids[$file]}", $m[0][1], strlen($m[0][0]));
         }
     }
     $this->html = $html;
     if ($this->getSubject() == NULL && ($matches = Strings::match($html, '#<title>(.+?)</title>#is'))) {
         // intentionally ==
         $this->setSubject(html_entity_decode($matches[1], ENT_QUOTES, 'UTF-8'));
     }
     if ($this->getBody() == NULL && $html != NULL) {
         // intentionally ==
         $this->setBody($this->buildText($html));
     }
     return $this;
 }
开发者ID:prcharom,项目名称:w-pps-reality,代码行数:37,代码来源:Message.php

示例10: logRequest

 /**
  * Logging navigation requested
  *
  * @param string $requestLine
  */
 private function logRequest($requestLine)
 {
     $requestLine = Strings::replace($requestLine, '[Navigation requested: ]');
     $requestLine = Strings::trim($requestLine);
     $matches = Strings::matchAll($requestLine, '~ ([^=]+)=([^,]+),?~');
     $request = [];
     foreach ($matches as $match) {
         $match[2] = $match[2] === 'true' ? true : ($match[2] === 'false' ? false : $match[2]);
         $request[$match[1]] = $match[2];
     }
     $this->requests[] = $request;
 }
开发者ID:lawondyss,项目名称:canterville,代码行数:17,代码来源:Casper.php

示例11: buildHtml

 /**
  * Builds HTML content.
  * @return void
  */
 protected function buildHtml()
 {
     if ($this->html instanceof Nette\Templating\ITemplate) {
         $this->html->mail = $this;
         if ($this->basePath === NULL && $this->html instanceof Nette\Templating\IFileTemplate) {
             $this->basePath = dirname($this->html->getFile());
         }
         $this->html = $this->html->__toString(TRUE);
     }
     if ($this->basePath !== FALSE) {
         $cids = array();
         $matches = Strings::matchAll($this->html, '#(src\\s*=\\s*|background\\s*=\\s*|url\\()(["\'])(?![a-z]+:|[/\\#])(.+?)\\2#i', PREG_OFFSET_CAPTURE);
         foreach (array_reverse($matches) as $m) {
             $file = rtrim($this->basePath, '/\\') . '/' . $m[3][0];
             if (!isset($cids[$file])) {
                 $cids[$file] = substr($this->addEmbeddedFile($file)->getHeader("Content-ID"), 1, -1);
             }
             $this->html = substr_replace($this->html, "{$m[1][0]}{$m[2][0]}cid:{$cids[$file]}{$m[2][0]}", $m[0][1], strlen($m[0][0]));
         }
     }
     if (!$this->getSubject() && ($matches = Strings::match($this->html, '#<title>(.+?)</title>#is'))) {
         $this->setSubject(html_entity_decode($matches[1], ENT_QUOTES, 'UTF-8'));
     }
 }
开发者ID:bazo,项目名称:Tatami,代码行数:28,代码来源:Message.php

示例12: matchAll

 public static function matchAll($subject, $pattern, $flags = 0, $offset = 0)
 {
     return Nette\Utils\Strings::matchAll($subject, $pattern, $flags, $offset);
 }
开发者ID:mesour,项目名称:components,代码行数:4,代码来源:Helpers.php

示例13: setMask

 /**
  * Parse mask and array of default values; initializes object.
  * @param  string
  * @param  array
  * @return void
  */
 private function setMask($mask, array $metadata)
 {
     $this->mask = $mask;
     // detect '//host/path' vs. '/abs. path' vs. 'relative path'
     if (preg_match('#(?:(https?):)?(//.*)#A', $mask, $m)) {
         $this->type = self::HOST;
         list(, $this->scheme, $mask) = $m;
     } elseif (substr($mask, 0, 1) === '/') {
         $this->type = self::PATH;
     } else {
         $this->type = self::RELATIVE;
     }
     foreach ($metadata as $name => $meta) {
         if (!is_array($meta)) {
             $metadata[$name] = $meta = [self::VALUE => $meta];
         }
         if (array_key_exists(self::VALUE, $meta)) {
             if (is_scalar($meta[self::VALUE])) {
                 $metadata[$name][self::VALUE] = (string) $meta[self::VALUE];
             }
             $metadata[$name]['fixity'] = self::CONSTANT;
         }
     }
     if (strpbrk($mask, '?<>[]') === FALSE) {
         $this->re = '#' . preg_quote($mask, '#') . '/?\\z#A';
         $this->sequence = [$mask];
         $this->metadata = $metadata;
         return;
     }
     // PARSE MASK
     // <parameter-name[=default] [pattern]> or [ or ] or ?...
     $parts = Strings::split($mask, '/<([^<>= ]+)(=[^<> ]*)? *([^<>]*)>|(\\[!?|\\]|\\s*\\?.*)/');
     $this->xlat = [];
     $i = count($parts) - 1;
     // PARSE QUERY PART OF MASK
     if (isset($parts[$i - 1]) && substr(ltrim($parts[$i - 1]), 0, 1) === '?') {
         // name=<parameter-name [pattern]>
         $matches = Strings::matchAll($parts[$i - 1], '/(?:([a-zA-Z0-9_.-]+)=)?<([^> ]+) *([^>]*)>/');
         foreach ($matches as list(, $param, $name, $pattern)) {
             // $pattern is not used
             if (isset(static::$styles['?' . $name])) {
                 $meta = static::$styles['?' . $name];
             } else {
                 $meta = static::$styles['?#'];
             }
             if (isset($metadata[$name])) {
                 $meta = $metadata[$name] + $meta;
             }
             if (array_key_exists(self::VALUE, $meta)) {
                 $meta['fixity'] = self::OPTIONAL;
             }
             unset($meta['pattern']);
             $meta['filterTable2'] = empty($meta[self::FILTER_TABLE]) ? NULL : array_flip($meta[self::FILTER_TABLE]);
             $metadata[$name] = $meta;
             if ($param !== '') {
                 $this->xlat[$name] = $param;
             }
         }
         $i -= 5;
     }
     // PARSE PATH PART OF MASK
     $brackets = 0;
     // optional level
     $re = '';
     $sequence = [];
     $autoOptional = TRUE;
     $aliases = [];
     do {
         $part = $parts[$i];
         // part of path
         if (strpbrk($part, '<>') !== FALSE) {
             throw new Nette\InvalidArgumentException("Unexpected '{$part}' in mask '{$mask}'.");
         }
         array_unshift($sequence, $part);
         $re = preg_quote($part, '#') . $re;
         if ($i === 0) {
             break;
         }
         $i--;
         $part = $parts[$i];
         // [ or ]
         if ($part === '[' || $part === ']' || $part === '[!') {
             $brackets += $part[0] === '[' ? -1 : 1;
             if ($brackets < 0) {
                 throw new Nette\InvalidArgumentException("Unexpected '{$part}' in mask '{$mask}'.");
             }
             array_unshift($sequence, $part);
             $re = ($part[0] === '[' ? '(?:' : ')?') . $re;
             $i -= 4;
             continue;
         }
         $pattern = trim($parts[$i]);
         $i--;
         // validation condition (as regexp)
//.........这里部分代码省略.........
开发者ID:nette,项目名称:application,代码行数:101,代码来源:Route.php

示例14: processPresenter

 /**
  * @param \SplFileInfo $file
  */
 private function processPresenter($file)
 {
     $stream = fopen("safe://" . $file->getRealPath(), 'r');
     $content = fread($stream, filesize("safe://" . $file->getRealPath()));
     fclose($stream);
     $module = String::match($content, '~(^|;)\\s*namespace (?P<name>[A-z0-9_-]+)Module;~m');
     $module = $module['name'];
     $presenter = String::match($content, '~(^|;)\\s*class (?P<name>[A-z0-9_-]+)Presenter(\\s|$)~m');
     if ($presenter === NULL || $presenter['name'] === 'Error') {
         return FALSE;
     }
     $presenter = $presenter['name'];
     $actions = array();
     foreach (String::matchAll($content, '~function (action|render)(?P<name>[A-z0-9_-]+)(\\s|\\()~') as $action) {
         $action = lcfirst($action['name']);
         if (array_search($action, $actions) === FALSE) {
             $actions[] = $action;
         }
     }
     return array($module, $presenter, $actions);
 }
开发者ID:rostenkowski,项目名称:NavigationPanel,代码行数:24,代码来源:NavigationPanel.php

示例15: parseComment

    /**
     * Parses phpDoc comment.
     * @param  string
     * @return array
     */
    private static function parseComment($comment)
    {
        static $tokens = array('true' => TRUE, 'false' => FALSE, 'null' => NULL, '' => TRUE);
        $res = array();
        $comment = preg_replace('#^\\s*\\*\\s?#ms', '', trim($comment, '/*'));
        $parts = preg_split('#^\\s*(?=@' . self::RE_IDENTIFIER . ')#m', $comment, 2);
        $description = trim($parts[0]);
        if ($description !== '') {
            $res['description'] = array($description);
        }
        $matches = Strings::matchAll(isset($parts[1]) ? $parts[1] : '', '~
				(?<=\\s|^)@(' . self::RE_IDENTIFIER . ')[ \\t]*      ##  annotation
				(
					\\((?>' . self::RE_STRING . '|[^\'")@]+)+\\)|  ##  (value)
					[^(@\\r\\n][^@\\r\\n]*|)                     ##  value
			~xi');
        foreach ($matches as $match) {
            list(, $name, $value) = $match;
            if (substr($value, 0, 1) === '(') {
                $items = array();
                $key = '';
                $val = TRUE;
                $value[0] = ',';
                while ($m = Strings::match($value, '#\\s*,\\s*(?>(' . self::RE_IDENTIFIER . ')\\s*=\\s*)?(' . self::RE_STRING . '|[^\'"),\\s][^\'"),]*)#A')) {
                    $value = substr($value, strlen($m[0]));
                    list(, $key, $val) = $m;
                    $val = rtrim($val);
                    if ($val[0] === "'" || $val[0] === '"') {
                        $val = substr($val, 1, -1);
                    } elseif (is_numeric($val)) {
                        $val = 1 * $val;
                    } else {
                        $lval = strtolower($val);
                        $val = array_key_exists($lval, $tokens) ? $tokens[$lval] : $val;
                    }
                    if ($key === '') {
                        $items[] = $val;
                    } else {
                        $items[$key] = $val;
                    }
                }
                $value = count($items) < 2 && $key === '' ? $val : $items;
            } else {
                $value = trim($value);
                if (is_numeric($value)) {
                    $value = 1 * $value;
                } else {
                    $lval = strtolower($value);
                    $value = array_key_exists($lval, $tokens) ? $tokens[$lval] : $value;
                }
            }
            $class = $name . 'Annotation';
            if (self::$useAnnotationClasses && class_exists($class)) {
                $res[$name][] = new $class(is_array($value) ? $value : array('value' => $value));
            } else {
                $res[$name][] = is_array($value) ? Nette\ArrayHash::from($value) : $value;
            }
        }
        return $res;
    }
开发者ID:eduardobenito10,项目名称:jenkins-php-quickstart,代码行数:65,代码来源:AnnotationsParser.php


注:本文中的Nette\Utils\Strings::matchAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。