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


PHP String::split方法代码示例

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


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

示例1: parseFile

 /**
  * Fix downloaded file
  * @throws \Curl\CurlException
  * @throws \InvalidStateException
  * @return \Curl\Response
  */
 private function parseFile()
 {
     if ($this->request->method === Request::DOWNLOAD) {
         $path_p = $this->request->downloadPath;
         @fclose($this->request->getOption('file'));
         // internationaly @
         if (($fp = @fopen($this->request->fileProtocol . '://' . $path_p, "rb")) === FALSE) {
             // internationaly @
             throw new \InvalidStateException("Fopen error for file '{$path_p}'");
         }
         $headers = String::split(@fread($fp, $this->request->info['header_size']), "~[\n\r]+~", PREG_SPLIT_NO_EMPTY);
         // internationaly @
         $this->Headers = array_merge($this->Headers, static::parseHeaders($headers));
         @fseek($fp, $this->request->info['header_size']);
         // internationaly @
         $path_t = $this->request->downloadPath . '.tmp';
         if (($ft = @fopen($this->request->fileProtocol . '://' . $path_t, "wb")) === FALSE) {
             // internationaly @
             throw new \InvalidStateException("Write error for file '{$path_t}' ");
         }
         while (!feof($fp)) {
             $row = fgets($fp, 4096);
             fwrite($ft, $row);
         }
         @fclose($fp);
         // internationaly @
         @fclose($ft);
         // internationaly @
         if (!@unlink($this->request->fileProtocol . '://' . $path_p)) {
             // internationaly @
             throw new \InvalidStateException("Error while deleting file {$path_p} ");
         }
         if (!@rename($path_t, $path_p)) {
             // internationaly @
             throw new \InvalidStateException("Error while renaming file '{$path_t}' to '" . basename($path_p) . "'. ");
         }
         chmod($path_p, 0755);
         if (!$this->Headers) {
             throw new CurlException("Headers parsing failed", NULL, $this);
         }
     }
     return $this;
 }
开发者ID:pavelmaca,项目名称:cURL-wrapper,代码行数:49,代码来源:Response.php

示例2: getOffset

	public function getOffset($i)
	{
		$tokens = String::split($this->input, $this->re, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE);
		list(, $offset) = $tokens[$i];
		return array(
			$offset,
			($offset ? substr_count($this->input, "\n", 0, $offset) + 1 : 1),
			$offset - strrpos(substr($this->input, 0, $offset), "\n"),
		);
	}
开发者ID:norbe,项目名称:AutoUse,代码行数:10,代码来源:Tokenizer.php

示例3: 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 (substr($mask, 0, 2) === '//') {
         $this->type = self::HOST;
     } 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] = array(self::VALUE => $meta, 'fixity' => self::CONSTANT);
         } elseif (array_key_exists(self::VALUE, $meta)) {
             $metadata[$name]['fixity'] = self::CONSTANT;
         }
     }
     // PARSE MASK
     $parts = String::split($mask, '/<([^># ]+) *([^>#]*)(#?[^>\\[\\]]*)>|(\\[!?|\\]|\\s*\\?.*)/');
     // <parameter-name [pattern] [#class]> or [ or ] or ?...
     $this->xlat = array();
     $i = count($parts) - 1;
     // PARSE QUERY PART OF MASK
     if (isset($parts[$i - 1]) && substr(ltrim($parts[$i - 1]), 0, 1) === '?') {
         $matches = String::matchAll($parts[$i - 1], '/(?:([a-zA-Z0-9_.-]+)=)?<([^># ]+) *([^>#]*)(#?[^>]*)>/');
         // name=<parameter-name [pattern][#class]>
         foreach ($matches as $match) {
             list(, $param, $name, $pattern, $class) = $match;
             // $pattern is not used
             if ($class !== '') {
                 if (!isset(self::$styles[$class])) {
                     throw new \InvalidStateException("Parameter '{$name}' has '{$class}' flag, but Route::\$styles['{$class}'] is not set.");
                 }
                 $meta = self::$styles[$class];
             } elseif (isset(self::$styles['?' . $name])) {
                 $meta = self::$styles['?' . $name];
             } else {
                 $meta = self::$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;
     }
     $brackets = 0;
     // optional level
     $re = '';
     $sequence = array();
     $autoOptional = array(0, 0);
     // strlen($re), count($sequence)
     do {
         array_unshift($sequence, $parts[$i]);
         $re = preg_quote($parts[$i], '#') . $re;
         if ($i === 0) {
             break;
         }
         $i--;
         $part = $parts[$i];
         // [ or ]
         if ($part === '[' || $part === ']' || $part === '[!') {
             $brackets += $part[0] === '[' ? -1 : 1;
             if ($brackets < 0) {
                 throw new \InvalidArgumentException("Unexpected '{$part}' in mask '{$mask}'.");
             }
             array_unshift($sequence, $part);
             $re = ($part[0] === '[' ? '(?:' : ')?') . $re;
             $i -= 4;
             continue;
         }
         $class = $parts[$i];
         $i--;
         // validation class
         $pattern = trim($parts[$i]);
         $i--;
         // validation condition (as regexp)
         $name = $parts[$i];
         $i--;
         // parameter name
         array_unshift($sequence, $name);
         if ($name[0] === '?') {
             // "foo" parameter
             $re = '(?:' . preg_quote(substr($name, 1), '#') . '|' . $pattern . ')' . $re;
             $sequence[1] = substr($name, 1) . $sequence[1];
//.........这里部分代码省略.........
开发者ID:nella,项目名称:ActiveMapper,代码行数:101,代码来源:Route.php

示例4: scanDirectory

 /**
  * Scan a directory for PHP files, subdirectories and 'netterobots.txt' file.
  * @param  string
  * @return void
  */
 private function scanDirectory($dir)
 {
     if (is_dir($dir)) {
         $disallow = array();
         $iterator = Nette\Finder::findFiles(String::split($this->acceptFiles, '#[,\\s]+#'))->filter(function ($file) use(&$disallow) {
             return !isset($disallow[$file->getPathname()]);
         })->from($dir)->exclude(String::split($this->ignoreDirs, '#[,\\s]+#'))->filter($filter = function ($dir) use(&$disallow) {
             $path = $dir->getPathname();
             if (is_file("{$path}/netterobots.txt")) {
                 foreach (file("{$path}/netterobots.txt") as $s) {
                     if ($matches = String::match($s, '#^disallow\\s*:\\s*(\\S+)#i')) {
                         $disallow[$path . str_replace('/', DIRECTORY_SEPARATOR, rtrim('/' . ltrim($matches[1], '/'), '/'))] = TRUE;
                     }
                 }
             }
             return !isset($disallow[$path]);
         });
         $filter(new \SplFileInfo($dir));
     } else {
         $iterator = new \ArrayIterator(array(new \SplFileInfo($dir)));
     }
     foreach ($iterator as $entry) {
         $path = $entry->getPathname();
         if (!isset($this->files[$path]) || $this->files[$path] !== $entry->getMTime()) {
             $this->scanScript($path);
         }
     }
 }
开发者ID:jff15,项目名称:travelbot,代码行数:33,代码来源:RobotLoader.php

示例5: error

 private function error()
 {
     $tokens = String::split($this->input, self::$regexp, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE);
     list($token, $offset) = $tokens[$this->n];
     $line = substr_count($this->input, "\n", 0, $offset) + 1;
     $col = $offset - strrpos(substr($this->input, 0, $offset), "\n");
     throw new \Exception('NEON parse error: unexpected ' . str_replace("\n", '\\n', substr($token, 0, 10)) . " on line {$line}, column {$col}.");
 }
开发者ID:nella,项目名称:ActiveMapper,代码行数:8,代码来源:NeonParser.php


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