本文整理汇总了PHP中Strings::split方法的典型用法代码示例。如果您正苦于以下问题:PHP Strings::split方法的具体用法?PHP Strings::split怎么用?PHP Strings::split使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Strings
的用法示例。
在下文中一共展示了Strings::split方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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
// <parameter-name[=default] [pattern] [#class]> or [ or ] or ?...
$parts = Strings::split($mask, '/<([^>#= ]+)(=[^># ]*)? *([^>#]*)(#?[^>\\[\\]]*)>|(\\[!?|\\]|\\s*\\?.*)/');
$this->xlat = array();
$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][#class]>
$matches = Strings::matchAll($parts[$i - 1], '/(?:([a-zA-Z0-9_.-]+)=)?<([^># ]+) *([^>#]*)(#?[^>]*)>/');
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 -= 6;
}
// PARSE PATH PART OF MASK
$brackets = 0;
// optional level
$re = '';
$sequence = array();
$autoOptional = TRUE;
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 -= 5;
continue;
}
$class = $parts[$i];
$i--;
// validation class
$pattern = trim($parts[$i]);
$i--;
// validation condition (as regexp)
$default = $parts[$i];
$i--;
// default value
$name = $parts[$i];
$i--;
// parameter name
array_unshift($sequence, $name);
if ($name[0] === '?') {
//.........这里部分代码省略.........
示例2: getOffset
/**
* Returns position of token in input string.
* @param int token number
* @return array [offset, line, column]
*/
public function getOffset($i)
{
$tokens = Strings::split($this->input, $this->re, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE);
$offset = isset($tokens[$i]) ? $tokens[$i][1] : strlen($this->input);
return array($offset, $offset ? substr_count($this->input, "\n", 0, $offset) + 1 : 1, $offset - strrpos(substr($this->input, 0, $offset), "\n"));
}